Class: Monadt::Maybe

Inherits:
Object
  • Object
show all
Extended by:
Adt
Defined in:
lib/monadt/maybe.rb

Constant Summary collapse

Just =
data :value
Nothing =
data

Class Method Summary collapse

Methods included from Adt

match, with

Class Method Details

.bind(m, &blk) ⇒ Object



11
12
13
14
15
# File 'lib/monadt/maybe.rb', line 11

def bind(m, &blk)
  match(m,
    with(Just) { |v| blk.call(v) },
    with(Nothing) { m })
end

.return(a) ⇒ Object



17
18
19
# File 'lib/monadt/maybe.rb', line 17

def return(a)
  Maybe.just a
end