Sha256: ea3abc8cee7b70e748130aaf0301c47c18ed2b36d656b64dd91fa57e1b95a66b
Contents?: true
Size: 774 Bytes
Versions: 10
Compression:
Stored size: 774 Bytes
Contents
#-- # Thanks dave! #++ class Proc # Returns a new proc that is the functional # compostion of two procs, in order. # # a = lambda { |x| x + 4 } # b = lambda { |y| y / 2 } # # a.compose(b).call(4) #=> 6 # b.compase(a).call(4) #=> 4 # def compose(g) raise ArgumentError, "arity count mismatch" unless arity == g.arity proc{ |*a| self[ *g[*a] ] } end end # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # =begin test require 'test/unit' class TCProc < Test::Unit::TestCase def test_compose a = lambda { |x| x + 4 } b = lambda { |y| y / 2 } assert_equal( 6, (a.compose(b)).call(4) ) assert_equal( 4, (b.compose(a)).call(4) ) end end =end
Version data entries
10 entries across 10 versions & 1 rubygems