From ad6f52e7f2c59581c5e4a6a0d6ff869739d17bd4 Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Mon, 19 Apr 2010 23:01:42 +0200 Subject: [PATCH 01/27] no args on stack --- lib/functional.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/functional.rb b/lib/functional.rb index dce2126..3d71850 100644 --- a/lib/functional.rb +++ b/lib/functional.rb @@ -9,7 +9,7 @@ class Functional def push_method code, *args, &exe name = "__meth_#{exe.object_id}" define_singleton_method name, &exe - @stack.push [code % name]+args + @stack.push code % name self end @@ -41,6 +41,6 @@ class Functional def each &exe return self unless exe - @obj.send @func || :each, *@args, &eval( "lambda{|value|#{@stack.join( ";")};exe.call(value)}") + @obj.send @func||:each, *@args, &eval( "lambda{|value|#{@stack.join ";"};exe.call(value)}") end end From 162dbb020c7050dd912bf9459af233c1abc1c070 Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Tue, 20 Apr 2010 16:50:59 +0200 Subject: [PATCH 02/27] eval -> many lambdas. #map added --- lib/functional.rb | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/lib/functional.rb b/lib/functional.rb index 3d71850..52c7a90 100644 --- a/lib/functional.rb +++ b/lib/functional.rb @@ -6,10 +6,8 @@ class Functional self.new.send meth, *args, &exe end - def push_method code, *args, &exe - name = "__meth_#{exe.object_id}" - define_singleton_method name, &exe - @stack.push code % name + def push_method meth, *args, &exe + @stack.push [meth, exe]+args self end @@ -18,12 +16,12 @@ class Functional end def collect &exe - push_method "value=%s(value)", &exe + push_method :collect, &exe end # map/reduce? def map &exe - raise "Reserved for MapReduce." + push_method :map, &exe end # map/reduce? @@ -32,15 +30,41 @@ class Functional end def select &exe - push_method "%s(value)||next", &exe + push_method :select, &exe end def delete_if &exe - push_method "%s(value)&&next", &exe + push_method :delete_if, &exe + end + + def compact + push_method :compact + end + + def together init, &exe + push_method :together, init, &exe end def each &exe return self unless exe - @obj.send @func||:each, *@args, &eval( "lambda{|value|#{@stack.join ";"};exe.call(value)}") + callstack = exe + @stack.reverse.each do |a| + m, e = *a[0..1] + pre = callstack + callstack = case m + 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 :delete_if then lambda {|val| pre.call val unless e.call val } + when :compact then lambda {|val| pre.call val if val } + when :together + buf = a[2] + lambda {|val| if e.call val then pre.call buf; buf = a[2]+val else buf += val end } + else + $stderr.puts "Whats that? #{m.inspect}" + callstack + end + end + @obj.send @func||:each, *@args, &callstack end end From bf67c1752f73fd07032e22150583d0a6e7eddf2a Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Tue, 20 Apr 2010 18:54:35 +0200 Subject: [PATCH 03/27] map&reduce: first step --- lib/functional.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/functional.rb b/lib/functional.rb index 52c7a90..c730497 100644 --- a/lib/functional.rb +++ b/lib/functional.rb @@ -53,13 +53,16 @@ class Functional pre = callstack callstack = case m 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 :delete_if then lambda {|val| pre.call val unless e.call 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 - buf = a[2] - lambda {|val| if e.call val then pre.call buf; buf = a[2]+val else buf += val end } + buf = a[2].dup + lambda {|val| if e.call val then pre.call buf; buf = a[2].dup+val else buf += val end } else $stderr.puts "Whats that? #{m.inspect}" callstack @@ -67,4 +70,8 @@ class Functional end @obj.send @func||:each, *@args, &callstack end + + def p + each &Kernel.method( :p) + end end From 8e883065ca64b56a3c5f979673cb8c11ebd743d1 Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Thu, 20 May 2010 14:48:42 +0200 Subject: [PATCH 04/27] Version 0.0.2 --- VERSION | 2 +- lib/functional.rb | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 8acdd82..4e379d2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.1 +0.0.2 diff --git a/lib/functional.rb b/lib/functional.rb index c730497..f2230e3 100644 --- a/lib/functional.rb +++ b/lib/functional.rb @@ -1,4 +1,25 @@ +class NotRegexp + def initialize r + @rx = r + end + def match l + ! @rx.match( l) + end + def =~ l + ! @rx =~ l + end + def -@ + @rx + end +end + +class Regexp + def -@ + NotRegexp.new self + end +end + class Functional include Enumerable @@ -33,6 +54,10 @@ class Functional push_method :select, &exe end + def grep r + push_method :select, &r.method( :match) + end + def delete_if &exe push_method :delete_if, &exe end From 63b6ac53b142d2f4fe2b7f9450c79da30672e53c Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Thu, 20 May 2010 17:07:23 +0200 Subject: [PATCH 05/27] Version 0.1.0: Vollstaendig neugeschrieben. Klassen statt Lambdas. Erweiterbar --- VERSION | 2 +- lib/functional.rb | 181 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 142 insertions(+), 41 deletions(-) diff --git a/VERSION b/VERSION index 4e379d2..6e8bf73 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.2 +0.1.0 diff --git a/lib/functional.rb b/lib/functional.rb index f2230e3..a7dbac6 100644 --- a/lib/functional.rb +++ b/lib/functional.rb @@ -23,26 +23,138 @@ end class Functional include Enumerable - def self.method_missing meth, *args, &exe - self.new.send meth, *args, &exe + class Base + attr_reader :exe + attr_accessor :next + def initialize &e + @exe = e + end + + def call *a + @next.call *a + end + + def end + @next.end + end end - def push_method meth, *args, &exe - @stack.push [meth, exe]+args + class Collect Date: Thu, 20 May 2010 21:28:39 +0200 Subject: [PATCH 06/27] 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 Date: Sun, 23 May 2010 22:20:53 +0200 Subject: [PATCH 07/27] NotRegexp -> NegRegexp. #map implemented. very simple. #reduce: not yet. --- lib/functional.rb | 64 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 18 deletions(-) diff --git a/lib/functional.rb b/lib/functional.rb index 632ae9d..3ddfab0 100644 --- a/lib/functional.rb +++ b/lib/functional.rb @@ -1,22 +1,28 @@ -class NotRegexp - def initialize r - @rx = r - end - def match l - ! @rx.match( l) - end - def =~ l - ! @rx =~ l +class ::Regexp + class NegRegexp + def initialize r + @rx = r + end + def match l + ! @rx.match( l) + end + def =~ l + ! @rx =~ l + end + def -@ + @rx + end end + def -@ - @rx + NegRegexp.new self end end -class Regexp - def -@ - NotRegexp.new self +class ::Object + def functional meth = nil + Functional.new self, meth end end @@ -37,6 +43,10 @@ class Functional def end @next.end end + + def to_proc + method( :call).to_proc + end end class Collect Date: Tue, 25 May 2010 19:02:49 +0200 Subject: [PATCH 08/27] MapReduce implementiert --- lib/functional.rb | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/functional.rb b/lib/functional.rb index 3ddfab0..ce407c0 100644 --- a/lib/functional.rb +++ b/lib/functional.rb @@ -24,6 +24,7 @@ class ::Object def functional meth = nil Functional.new self, meth end + alias to_fun functional end class Functional @@ -149,19 +150,24 @@ class Functional class Map Date: Tue, 25 May 2010 19:04:03 +0200 Subject: [PATCH 09/27] Version 0.1.1 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 6e8bf73..17e51c3 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.0 +0.1.1 From 95a3027926ca97f7ae50c5db0171f3dcc087b967 Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Wed, 23 Jun 2010 16:40:01 +0200 Subject: [PATCH 10/27] flatten added --- lib/functional.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/functional.rb b/lib/functional.rb index ce407c0..7faf71d 100644 --- a/lib/functional.rb +++ b/lib/functional.rb @@ -154,6 +154,12 @@ class Functional end end + class Flatten Date: Wed, 23 Jun 2010 17:01:01 +0200 Subject: [PATCH 11/27] more example in README.md --- README.md | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d625a86..c8db4a8 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,45 @@ Usage require 'functional' - obj = 0 .. 10**12 - Functional.new( obj).select {|i| i.even? }.collect {|i| i/3 }.select {|i| i.even? }.each &method( :puts) + # To demonstrate Functional, we create a Class with a infinite loop: + class Sequence + include Enumerable + def initialize first = 0, step = 1 + @i, @step = first, step + end + def each + # Our infinite loop: + loop do + yield @i + @i += @step + end + end + end + + Functional.new( Sequence.new). + select {|i| i.even? }. + collect {|i| i/3 }. + select {|i| i.even?}. + collect {|i| [[[[[[i.even?, i.odd?]]], i, [[[[[[i.class]]]]]]]]] }. + flatten. # It flattens everything! Not like: collect {|i| i.flatten }. + p + + # Without Functional... Bye bye. + Sequence.new. + select {|i| i.even? }. + collect {|i| i/3 }. + select {|i| i.even?}. + collect {|i| [[[[[[i.even?, i.odd?]]], i, [[[[[[i.class]]]]]]]]] }. + flatten. # It flattens everything! Not like: collect {|i| i.flatten }. + p + +It will never realize, that #p doesn't exists, because the first select runs endless. +Functional#p prints everything to stdout. + + (0..100000).to_fun. + collect {|i| i*3 }. + select {|i| i%5 == 2 }. + to_a What's with _#map_? ================= From 275183d346c843f582a1c74a21588330a1e8f717 Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Wed, 23 Jun 2010 17:01:43 +0200 Subject: [PATCH 12/27] more example in README.md... 2 spaces replaced --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c8db4a8..78876b7 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Usage @i += @step end end - end + end Functional.new( Sequence.new). select {|i| i.even? }. From 362a98754495225b5ac69c7d22c62c612a17f88f Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Tue, 30 Nov 2010 14:36:38 +0100 Subject: [PATCH 13/27] save, reduce, cons, slice, with_index added --- lib/functional.rb | 196 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 160 insertions(+), 36 deletions(-) diff --git a/lib/functional.rb b/lib/functional.rb index 7faf71d..37edbb9 100644 --- a/lib/functional.rb +++ b/lib/functional.rb @@ -21,10 +21,30 @@ class ::Regexp end class ::Object - def functional meth = nil + def to_fun meth = nil Functional.new self, meth end - alias to_fun functional +end + +class Counter + include Enumerable + attr_reader :c + + def initialize first = nil, step = nil + @c, @step = first || 0, step || 1 + end + + def next; @c += @step end + def to_i; c.to_i end + def to_f; c.to_f end + + def + i + @c += @step*i + end + + def each &e + loop { e.call self; self.next } + end end class Functional @@ -45,6 +65,10 @@ class Functional @next.end end + def clean + @next.clean + end + def to_proc method( :call).to_proc end @@ -120,6 +144,7 @@ class Functional def end nil end + alias :clean :end end class P @buf.size + @next.call @buf + @buf.clear + end + end + + def end + @next.call @buf + @next.end + end + end + + class Cons @buf.size + class < @buf.size + @next.end + end + end + + class Pager [ [0, _A], [1, _B], ..., [_I, _C], ..., [_N, _D]] + # [ [_A|_As], [_B|_Bs], ..., [_C|_Cs], ..., [_D|_Ds] ] ==> [ [0,_A|_As], [1,_B|_Bs], ..., [_I,_C|_Cs], ..., [_N,_D|_Ds] ] + def with_index &exe + i = 0 + exe ||= Array.method :[] + push Collect.new {|*a| exe.call i, *a } + end + + def slice n, &e + push Slice.new( n) + push Collect.new( &e) if e + self + end + + def cons n, &e + push Cons.new( n) + push Collect.new( &e) if e + self + end + + class Save < Base + attr_reader :db + + def initialize db + @db = db + end + + def call k, *v + @db[ k] = v.length == 1 ? v.first : v + end + end + + def save db + push Save.new( db) end end - -begin - require 'tokyocabinet' - - class Functional - class Map Date: Tue, 30 Nov 2010 14:45:06 +0100 Subject: [PATCH 14/27] reduce fix --- lib/functional.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/functional.rb b/lib/functional.rb index 37edbb9..2100835 100644 --- a/lib/functional.rb +++ b/lib/functional.rb @@ -186,7 +186,7 @@ class Functional end class Reduce Date: Sun, 13 Feb 2011 16:53:14 +0100 Subject: [PATCH 15/27] added: tap. delete_if -> filter (delete_if manipulates self, but Functional never, so filter is better). reduce |-> inject (it is like Array#inject) --- lib/functional.rb | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/functional.rb b/lib/functional.rb index 2100835..48b7f23 100644 --- a/lib/functional.rb +++ b/lib/functional.rb @@ -80,13 +80,20 @@ class Functional end end + class Tap Date: Sun, 13 Feb 2011 16:53:58 +0100 Subject: [PATCH 16/27] VERSION=0.1.2 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 17e51c3..d917d3e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.1 +0.1.2 From a97c4ed1f9c2fce22b5a5fc46d119c17e829fd65 Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Sun, 13 Feb 2011 17:38:13 +0100 Subject: [PATCH 17/27] oops. #reduce is better than #inject --- lib/functional.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/functional.rb b/lib/functional.rb index 48b7f23..7c6e23a 100644 --- a/lib/functional.rb +++ b/lib/functional.rb @@ -192,7 +192,7 @@ class Functional end end - class Inject Date: Mon, 21 Nov 2011 11:38:06 +0100 Subject: [PATCH 18/27] [].to_fun.reduce( []) # => Ups. [] will not be duped, so every key will have the same value. Argument for #reduce removed and everytime it will be an Array. --- lib/functional.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/functional.rb b/lib/functional.rb index 7c6e23a..611891a 100644 --- a/lib/functional.rb +++ b/lib/functional.rb @@ -1,4 +1,3 @@ - class ::Regexp class NegRegexp def initialize r @@ -193,10 +192,9 @@ class Functional end class Reduce Date: Thu, 24 Nov 2011 11:35:08 +0100 Subject: [PATCH 19/27] renamed call-functions. every call is an alias for a meaningful function-name. useful for debugging. --- lib/functional.rb | 68 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 20 deletions(-) diff --git a/lib/functional.rb b/lib/functional.rb index 611891a..4d2142c 100644 --- a/lib/functional.rb +++ b/lib/functional.rb @@ -49,16 +49,23 @@ end class Functional include Enumerable + class DEFAULT + end + class Base attr_reader :exe attr_accessor :next + attr_reader :caller + def initialize &e + @caller = Kernel.caller.first @exe = e end - def call *a + def base_fun *a @next.call *a end + alias call base_fun def end @next.end @@ -74,34 +81,39 @@ class Functional end class Collect @buf.size @next.call @buf @buf.clear end end + alias call slice_fun def end @next.call @buf @@ -231,7 +257,7 @@ class Functional @buf, @n = [], n end - def call *a + def cons_fun *a @buf.push a unless @n > @buf.size class < @buf.size @@ -267,9 +294,10 @@ class Functional @pager.puts a.inspect end - def call *a + def pager_fun *a @pager.puts a end + alias call pager_fun def clean @pager.close @@ -300,8 +328,8 @@ class Functional push Map.new( &exe) end - def reduce &exe - push Reduce.new( &exe) + def reduce iv = ::Functional::DEFAULT, &exe + push Reduce.new( iv, &exe) end def select &exe From 11128ea13131b142e5788de1c78b80bf23f3b9c1 Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Thu, 24 Nov 2011 11:47:03 +0100 Subject: [PATCH 20/27] README.md: methodphitamine & makros. VERSION 0.1.3 --- README.md | 43 +++++++++++++++++++++++++++++++++++++++++++ VERSION | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 78876b7..6cf2106 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,49 @@ Functional#p prints everything to stdout. select {|i| i%5 == 2 }. to_a +Thanks to `Symbol#to_proc`: + + Sequence.new.to_fun. + select( &:even?). + collect {|i| i/3 }. + select( &:even?). + collect {|i| [[[[[[i.even?, i.odd?]]], i, [[[[[[i.class]]]]]]]]] }. + flatten. # It flattens everything! Not like: collect {|i| i.flatten }. + p + +If you know methodphitamine, combine it: + + require 'methodphitamine' + + Sequence.new.to_fun. + select( &it.even?). + collect( &it/3). + select( &it.even?). + collect {|i| [[[[[[i.even?, i.odd?]]], i, [[[[[[i.class]]]]]]]]] }. + flatten. + p + + (0..100000).to_fun. + collect( &it*3). + select( &it%5 == 2). + to_a + +Makros +====== + + seq = Sequence.new.to_fun + seq = seq.select &it.even? if must_be_even + seq = seq. + collect( &it/3). + select( &it.even?). + collect {|i| [[[[[[i.even?, i.odd?]]], i, [[[[[[i.class]]]]]]]]] } + seq = seq.flatten if please_flatten + if print_it + seq.p + else + seq_to_a + end + What's with _#map_? ================= diff --git a/VERSION b/VERSION index d917d3e..b1e80bb 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.2 +0.1.3 From 77d2cfb488d6f3a81fb358c301dec3582dd75f9f Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Thu, 24 Nov 2011 11:48:24 +0100 Subject: [PATCH 21/27] .gitignore created --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6f69607 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +functional.gemspec From 29e7a0e4e222569000795d41de185cd0c0d72097 Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Thu, 24 Nov 2011 11:50:08 +0100 Subject: [PATCH 22/27] ignore pkg-dir --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 6f69607..8146014 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ functional.gemspec +pkg From 53033b8cdd09897ae510bf9700b07523e7319d67 Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Fri, 16 Dec 2011 11:22:48 +0100 Subject: [PATCH 23/27] bugfixes; tap. v0.1.4 --- VERSION | 2 +- lib/functional.rb | 58 +++++++++++++++++++++++++++++++++++------------ 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/VERSION b/VERSION index b1e80bb..845639e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.3 +0.1.4 diff --git a/lib/functional.rb b/lib/functional.rb index 4d2142c..715db4d 100644 --- a/lib/functional.rb +++ b/lib/functional.rb @@ -47,6 +47,7 @@ class Counter end class Functional + def self.__version__() '0.1.4' end include Enumerable class DEFAULT @@ -161,6 +162,11 @@ class Functional end class Each Date: Fri, 16 Dec 2011 11:42:45 +0100 Subject: [PATCH 24/27] tests added --- test/functional_test.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 test/functional_test.rb diff --git a/test/functional_test.rb b/test/functional_test.rb new file mode 100644 index 0000000..20aa11e --- /dev/null +++ b/test/functional_test.rb @@ -0,0 +1,14 @@ +require 'test/unit' +require 'functional' + +class FunTest < Test::Unit::TestCase + def test_to_fun_exists + assert_respond_to Object, :to_fun + end + + def test_to_fun_to_a + assert_equal (0..100).to_a, (0..100).to_fun.to_a + end + + +end From 99a268a89df5e61cea9abecc8ed37432d82e9c42 Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Fri, 16 Dec 2011 12:45:22 +0100 Subject: [PATCH 25/27] more tests --- test/functional_test.rb | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/test/functional_test.rb b/test/functional_test.rb index 20aa11e..9497c66 100644 --- a/test/functional_test.rb +++ b/test/functional_test.rb @@ -2,13 +2,28 @@ require 'test/unit' require 'functional' class FunTest < Test::Unit::TestCase + M = 0..100 + + def doit_fun m, &exe + f = m.to_fun + yield f + f.to_a + end + def test_to_fun_exists assert_respond_to Object, :to_fun end - def test_to_fun_to_a - assert_equal (0..100).to_a, (0..100).to_fun.to_a + def test_to_a + assert_equal M.to_a, doit_fun( M) {|x| x } end - + def test_collect + l = lambda {|x| x*2} + assert_equal M.collect( &l), doit_fun( M) {|x| x.collect( &l) } + end + + def test_inject + assert_equal M.inject( 0) {|i,j| i+j }, M.to_fun.inject( 0) {|i,j| i+j } + end end From 145129641db7eddaf34022cc8ec490bf39e0c923 Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Fri, 16 Dec 2011 12:45:52 +0100 Subject: [PATCH 26/27] v0.1.5 --- VERSION | 2 +- lib/functional.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 845639e..9faa1b7 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.4 +0.1.5 diff --git a/lib/functional.rb b/lib/functional.rb index 715db4d..f129e3d 100644 --- a/lib/functional.rb +++ b/lib/functional.rb @@ -47,7 +47,7 @@ class Counter end class Functional - def self.__version__() '0.1.4' end + def self.__version__() '0.1.5' end include Enumerable class DEFAULT From ede467e93492852712684bb1e46e7fc9ce986667 Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Fri, 3 Dec 2021 18:40:08 +0100 Subject: [PATCH 27/27] =?UTF-8?q?=E2=80=9EREADME.md=E2=80=9C=20=C3=A4ndern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 6cf2106..1478272 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ +Obsolete +======== + +Use `#lazy`. + Install =======