functional 0.0.0 → 0.0.1
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.
- data/README.md +6 -1
- data/VERSION +1 -1
- data/lib/functional.rb +9 -10
- 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? }.
|
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.
|
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
|
-
|
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
|
40
|
-
return
|
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
|