Compare commits

..

No commits in common. "master" and "v0.1.3" have entirely different histories.

5 changed files with 15 additions and 80 deletions

1
.gitignore vendored
View file

@ -1,2 +1 @@
functional.gemspec
pkg

View file

@ -1,8 +1,3 @@
Obsolete
========
Use `#lazy`.
Install
=======

View file

@ -1 +1 @@
0.1.5
0.1.3

View file

@ -47,7 +47,6 @@ class Counter
end
class Functional
def self.__version__() '0.1.5' end
include Enumerable
class DEFAULT
@ -162,11 +161,6 @@ class Functional
end
class Each <Base
def each_fun *a
@exe.call *a
end
alias call each_fun
def end
nil
end
@ -219,42 +213,25 @@ class Functional
super *a, &exe
iv = Array.method :new if ::Functional::DEFAULT == iv
@buf = if iv.kind_of?( ::Proc) || iv.kind_of?( ::Method)
p default: :proc, iv: iv
Hash.new {|h,k| h[k] = iv.call }
else
p default: :value, iv: iv
{}.tap {|h| h.default = iv }
end
end
def reduce_fun k, *a
@buf[ k] = @exe.call k, @buf[ k], *a
def reduce_fun *a
@buf[ a[0]] = @exe.call @buf[ a[0]], *a[1..-1]
end
alias call reduce_fun
def end
@buf.each &@next.method( :call)
@buf.each {|i| @next.call *i}
@next.end
end
end
class ToHash <Base
def initialize
super
@buf = {}
end
def to_hash_fun k, *a
@buf[k] = a
end
alias call to_hash_fun
def end
@buf
end
def clean
end
end
class Slice <Base
def initialize n
@buf, @n = [], n
@ -366,7 +343,6 @@ class Functional
def filter &exe
push Filter.new( &exe)
end
alias reject filter
def compact
push Compact.new
@ -386,12 +362,8 @@ class Functional
def each &exe
return self unless exe
push Each.new( &exe)
run
end
def to_hash
push ToHash.new
push Each.new
push exe
run
end
@ -430,21 +402,19 @@ class Functional
def with_index &exe
i = 0
exe ||= Array.method :[]
push Collect.new {|*a| exe.call i, *a; i += 1 }
push Collect.new {|*a| exe.call i, *a }
end
def slice n, &exe
def slice n, &e
push Slice.new( n)
block_given? ? self.collect( &exe) : self
push Collect.new( &e) if e
self
end
def cons n, &exe
def cons n, &e
push Cons.new( n)
block_given? ? self.collect( &exe) : self
end
def tap &exe
push Tap.new( &exe)
push Collect.new( &e) if e
self
end
class Save < Base

View file

@ -1,29 +0,0 @@
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_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