Guest User

Untitled

a guest
Apr 20th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1.  
  2. class Funk
  3. @@lib = {}
  4. @@lib[:id]= self.new{|x|;x}
  5. @@lib[:compose]= self.new{|funks|
  6.  
  7. funks = funks.reverse.map do |f|
  8. case f
  9. when Symbol
  10. return self.lib(f)
  11. when Array
  12. return @@lib[:compose].apply(*f)
  13. else
  14. return f
  15. end
  16. end
  17.  
  18. self.new{|arg|
  19. funks.inject(arg) do |mem,f|
  20. mem = x.apply(mem)
  21. end
  22. }
  23. }
  24.  
  25. def lib
  26. @@lib ||= {}
  27. end
  28.  
  29. def initialize(&block)
  30. if block_given?
  31. @block = block
  32. else @block = Proc.new{nil}
  33. end
  34. end
  35.  
  36. def apply(x)
  37. @block.call(x)
  38. end
  39.  
  40. def define(&block)
  41. if block_given?
  42. @block=block
  43. else
  44. end
  45. end
  46. end
Add Comment
Please, Sign In to add comment