Class: Maybe

Inherits:
Object
  • Object
show all
Extended by:
Monad, MonadPlus
Defined in:
lib/do_notation/monads/maybe.rb

Class Method Summary collapse

Methods included from Monad

bind_const, compose, run

Methods included from MonadPlus

guard

Class Method Details

.bind(value, &f) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/do_notation/monads/maybe.rb', line 11

def self.bind value, &f
  if value.nil?
    nil
  else
    f.call(value)
  end
end

.mplus(a, b) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/do_notation/monads/maybe.rb', line 25

def self.mplus a, b
  if b.nil?
    a
  else
    b
  end
end

.mzeroObject



21
22
23
# File 'lib/do_notation/monads/maybe.rb', line 21

def self.mzero
  unit(nil)
end

.unit(value) ⇒ Object



7
8
9
# File 'lib/do_notation/monads/maybe.rb', line 7

def self.unit value
  value
end