functional 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/functional.rb +44 -14
  3. metadata +3 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
data/lib/functional.rb CHANGED
@@ -47,6 +47,7 @@ class Counter
47
47
  end
48
48
 
49
49
  class Functional
50
+ def self.__version__() '0.1.4' end
50
51
  include Enumerable
51
52
 
52
53
  class DEFAULT
@@ -161,6 +162,11 @@ class Functional
161
162
  end
162
163
 
163
164
  class Each <Base
165
+ def each_fun *a
166
+ @exe.call *a
167
+ end
168
+ alias call each_fun
169
+
164
170
  def end
165
171
  nil
166
172
  end
@@ -213,25 +219,42 @@ class Functional
213
219
  super *a, &exe
214
220
  iv = Array.method :new if ::Functional::DEFAULT == iv
215
221
  @buf = if iv.kind_of?( ::Proc) || iv.kind_of?( ::Method)
216
- p default: :proc, iv: iv
217
222
  Hash.new {|h,k| h[k] = iv.call }
218
223
  else
219
- p default: :value, iv: iv
220
224
  {}.tap {|h| h.default = iv }
221
225
  end
222
226
  end
223
227
 
224
- def reduce_fun *a
225
- @buf[ a[0]] = @exe.call @buf[ a[0]], *a[1..-1]
228
+ def reduce_fun k, *a
229
+ @buf[ k] = @exe.call k, @buf[ k], *a
226
230
  end
227
231
  alias call reduce_fun
228
232
 
229
233
  def end
230
- @buf.each {|i| @next.call *i}
234
+ @buf.each &@next.method( :call)
231
235
  @next.end
232
236
  end
233
237
  end
234
238
 
239
+ class ToHash <Base
240
+ def initialize
241
+ super
242
+ @buf = {}
243
+ end
244
+
245
+ def to_hash_fun k, *a
246
+ @buf[k] = a
247
+ end
248
+ alias call to_hash_fun
249
+
250
+ def end
251
+ @buf
252
+ end
253
+
254
+ def clean
255
+ end
256
+ end
257
+
235
258
  class Slice <Base
236
259
  def initialize n
237
260
  @buf, @n = [], n
@@ -343,6 +366,7 @@ class Functional
343
366
  def filter &exe
344
367
  push Filter.new( &exe)
345
368
  end
369
+ alias reject filter
346
370
 
347
371
  def compact
348
372
  push Compact.new
@@ -362,8 +386,12 @@ class Functional
362
386
 
363
387
  def each &exe
364
388
  return self unless exe
365
- push Each.new
366
- push exe
389
+ push Each.new( &exe)
390
+ run
391
+ end
392
+
393
+ def to_hash
394
+ push ToHash.new
367
395
  run
368
396
  end
369
397
 
@@ -402,19 +430,21 @@ class Functional
402
430
  def with_index &exe
403
431
  i = 0
404
432
  exe ||= Array.method :[]
405
- push Collect.new {|*a| exe.call i, *a }
433
+ push Collect.new {|*a| exe.call i, *a; i += 1 }
406
434
  end
407
435
 
408
- def slice n, &e
436
+ def slice n, &exe
409
437
  push Slice.new( n)
410
- push Collect.new( &e) if e
411
- self
438
+ block_given? ? self.collect( &exe) : self
412
439
  end
413
440
 
414
- def cons n, &e
441
+ def cons n, &exe
415
442
  push Cons.new( n)
416
- push Collect.new( &e) if e
417
- self
443
+ block_given? ? self.collect( &exe) : self
444
+ end
445
+
446
+ def tap &exe
447
+ push Tap.new( &exe)
418
448
  end
419
449
 
420
450
  class Save < Base
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 3
9
- version: 0.1.3
8
+ - 4
9
+ version: 0.1.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Denis Knauf
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-11-24 00:00:00 +01:00
17
+ date: 2011-12-16 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies: []
20
20