From aaa7f106c8dea90f566d0b28f78c680bdbab14a1 Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Thu, 20 May 2010 21:28:39 +0200 Subject: [PATCH] MapReduce: first code - needs tokyocabinet --- lib/functional.rb | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/lib/functional.rb b/lib/functional.rb index a7dbac6..632ae9d 100644 --- a/lib/functional.rb +++ b/lib/functional.rb @@ -152,14 +152,12 @@ class Functional push Collect.new( &exe) end - # map/reduce? - def map &exe - push Map.new( &exe) + def map *a, &exe + raise "Reserved for MapReduce. Install TokyoCabinet, if you want to use it." end - # map/reduce? - def reduce &exe - raise "Reserved for MapReduce." + def reduce *a, &exe + raise "Reserved for MapReduce. Install TokyoCabinet, if you want to use it." end def select &exe @@ -187,11 +185,17 @@ class Functional end def each &exe + return self unless exe push Each.new push exe run end + def join deli + push Inject.new('') {|i,j|i+deli+j} + run + end + def run @obj.send @func||:each, *@args, &@next.method(:call) @next.end @@ -201,3 +205,31 @@ class Functional each &Kernel.method( :p) end end + +begin + require 'tokyocabinet' + + class Functional + class Map