class Monads::Maybe

Public Class Methods

unit(value) click to toggle source
unit

a -> M a

# File lib/ruby-monads/maybe.rb, line 6
def self.unit(value)
  value.nil? || value.is_a?(Nothing) ? Nothing.new : Just.new(value)
end

Public Instance Methods

bind(&block) click to toggle source
bind

(a -> M b) -> M a -> M b

# File lib/ruby-monads/maybe.rb, line 11
def bind(&block)
  ensure_monadic_result(&block).call
end
unwrap(default_value) click to toggle source
unwrap

a -> M a -> a

# File lib/ruby-monads/maybe.rb, line 16
def unwrap(default_value)
  @value || default_value
end

Private Instance Methods

monad_type() click to toggle source
# File lib/ruby-monads/maybe.rb, line 22
def monad_type
  Maybe
end