class EasyMonads::Monadic
Public Class Methods
unit(*args)
click to toggle source
# File lib/easy_monads/monadic.rb, line 7 def unit(*args) new(*args) end
Public Instance Methods
<=>(other_monad)
click to toggle source
# File lib/easy_monads/monadic.rb, line 39 def <=>(other_monad) return RuntimeError.new("Can only compare with other Monadic objects") unless other_monad.is_a? EasyMonads::Monadic data <=> other_monad.data end
==(other_monad)
click to toggle source
# File lib/easy_monads/monadic.rb, line 34 def ==(other_monad) return false unless other_monad.is_a? EasyMonads::Monadic data == other_monad.data end
bind(&func)
click to toggle source
# File lib/easy_monads/monadic.rb, line 16 def bind(&func) result = func.call(data) if defined? @data raise RuntimeError.new("Result of .bind must be a Monadic but was #{result.class.name}") unless result.is_a? Monadic result end
bind_unit(&func)
click to toggle source
# File lib/easy_monads/monadic.rb, line 22 def bind_unit(&func) self.bind { |*args| self.unit(func.call(*args)) } end
data()
click to toggle source
# File lib/easy_monads/monadic.rb, line 26 def data @data end
each() { |data| ... }
click to toggle source
# File lib/easy_monads/monadic.rb, line 30 def each yield data end
unit(to_wrap)
click to toggle source
# File lib/easy_monads/monadic.rb, line 12 def unit(to_wrap) self.class.unit(to_wrap) end