Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Funk
- @@lib = {}
- @@lib[:id]= self.new{|x|;x}
- @@lib[:compose]= self.new{|funks|
- funks = funks.reverse.map do |f|
- case f
- when Symbol
- return self.lib(f)
- when Array
- return @@lib[:compose].apply(*f)
- else
- return f
- end
- end
- self.new{|arg|
- funks.inject(arg) do |mem,f|
- mem = x.apply(mem)
- end
- }
- }
- def lib
- @@lib ||= {}
- end
- def initialize(&block)
- if block_given?
- @block = block
- else @block = Proc.new{nil}
- end
- end
- def apply(x)
- @block.call(x)
- end
- def define(&block)
- if block_given?
- @block=block
- else
- end
- end
- end
Add Comment
Please, Sign In to add comment