21 June 2007 and
Function composition is a common concept in functional programming languages. This first episode of ‘Ruby Banter’ shows you how to do it in Ruby.
21 June 2007 and
Function composition is a common concept in functional programming languages. This first episode of ‘Ruby Banter’ shows you how to do it in Ruby.
# Contains code by Eric Kidd, Peter Burns, and Ola Bini
lambda {|n| eval(str) }
end
b ||= f
lambda {|*args| !b.call(*args) }
end
a.map! {|b| b.to_proc }
if a.length == 2
# this is where it all happens, the rest is recursion
lambda {|*args| a[0].call(a[1].call(*args)) }
elsif a.length > 2
compose(a.shift, compose(*a))
else
lambda {nil }
end
end
lambda {|*args| a.all? {|f| f.call(*args) } }
end
lambda {|*args| a.any? {|f| f.call(*args) } }
end