functional 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +6 -1
  2. data/VERSION +1 -1
  3. data/lib/functional.rb +9 -10
  4. metadata +2 -2
data/README.md CHANGED
@@ -9,4 +9,9 @@ Usage
9
9
  require 'functional'
10
10
 
11
11
  obj = 0 .. 10**12
12
- Functional.new( obj).select {|i| i.even? }.map {|i| i/3 }.select {|i| i.even? }.each &method( :puts)
12
+ Functional.new( obj).select {|i| i.even? }.collect {|i| i/3 }.select {|i| i.even? }.each &method( :puts)
13
+
14
+ What's with _#map_?
15
+ =================
16
+
17
+ Do you know MapReduce? In future #map will be used for MapReduce. Use #collect.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
data/lib/functional.rb CHANGED
@@ -21,12 +21,15 @@ class Functional
21
21
  push_method "value=%s(value)", &exe
22
22
  end
23
23
 
24
- =begin
25
24
  # map/reduce?
26
25
  def map &exe
27
- push_method "value=%s(value)", &exe
26
+ raise "Reserved for MapReduce."
27
+ end
28
+
29
+ # map/reduce?
30
+ def reduce &exe
31
+ raise "Reserved for MapReduce."
28
32
  end
29
- =end
30
33
 
31
34
  def select &exe
32
35
  push_method "%s(value)||next", &exe
@@ -36,12 +39,8 @@ class Functional
36
39
  push_method "%s(value)&&next", &exe
37
40
  end
38
41
 
39
- def each obj, &exe
40
- return Enumerator.new self, :each, obj unless exe
41
- obj.each &eval( "lambda{|value|#{@stack.join( ";")};exe.call(value)}")
42
- end
43
-
44
- def inject obj, start, &exe
45
- each( obj).inject start, &exe
42
+ def each &exe
43
+ return self unless exe
44
+ @obj.send @func || :each, *@args, &eval( "lambda{|value|#{@stack.join( ";")};exe.call(value)}")
46
45
  end
47
46
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 0
9
- version: 0.0.0
8
+ - 1
9
+ version: 0.0.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Denis Knauf