lib/funkr/extensions/array.rb in funkr-0.0.25 vs lib/funkr/extensions/array.rb in funkr-0.0.26
- old
+ new
@@ -15,13 +15,14 @@
# Array is already a functor with its correct map implementation
# Array can be made an applicative functor, for example :
- # f = Array.curry_lift_proc{|x,y| x + y}
- # f.apply([0,4]).apply([5,7]) => [5, 7, 9, 11]
- # f.apply([0,4]).apply([]) => []
+ #
+ # f = Array.curry_lift_proc{|x,y| x + y}
+ # f.apply([0,4]).apply([5,7]) => [5, 7, 9, 11]
+ # f.apply([0,4]).apply([]) => []
include Applicative
extend Applicative::ClassMethods
def apply(to)
map do |f|
@@ -47,13 +48,15 @@
def mplus(m_y)
self + m_y
end
- # Array is also a monad
include Monad
extend Monad::ClassMethods
+ # Array is also a monad
+ #
+ # [1,2].bind{|x| [3,4].bind{|y| x + y}} # => [4,5,5,6]
def bind(&block)
self.map(&block).flatten(1)
end
def self.box(value)