map&reduce: first step
This commit is contained in:
parent
162dbb020c
commit
bf67c1752f
|
@ -53,13 +53,16 @@ class Functional
|
||||||
pre = callstack
|
pre = callstack
|
||||||
callstack = case m
|
callstack = case m
|
||||||
when :collect then lambda {|val| pre.call e.call( val) }
|
when :collect then lambda {|val| pre.call e.call( val) }
|
||||||
when :map then lambda {|val| e.call( val).each &pre }
|
|
||||||
when :select then lambda {|val| pre.call val if e.call val }
|
when :select then lambda {|val| pre.call val if e.call val }
|
||||||
when :delete_if then lambda {|val| pre.call val unless e.call val }
|
when :delete_if then lambda {|val| pre.call val unless e.call val }
|
||||||
when :compact then lambda {|val| pre.call val if val }
|
when :compact then lambda {|val| pre.call val if val }
|
||||||
|
when :map then lambda {|val| e.call( val).each &pre }
|
||||||
|
when :reduce
|
||||||
|
buf = {}
|
||||||
|
lambda {|val| buf[ val.first] = e.call( *val) }
|
||||||
when :together
|
when :together
|
||||||
buf = a[2]
|
buf = a[2].dup
|
||||||
lambda {|val| if e.call val then pre.call buf; buf = a[2]+val else buf += val end }
|
lambda {|val| if e.call val then pre.call buf; buf = a[2].dup+val else buf += val end }
|
||||||
else
|
else
|
||||||
$stderr.puts "Whats that? #{m.inspect}"
|
$stderr.puts "Whats that? #{m.inspect}"
|
||||||
callstack
|
callstack
|
||||||
|
@ -67,4 +70,8 @@ class Functional
|
||||||
end
|
end
|
||||||
@obj.send @func||:each, *@args, &callstack
|
@obj.send @func||:each, *@args, &callstack
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def p
|
||||||
|
each &Kernel.method( :p)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Reference in a new issue