Class: Fr::Maybe

Inherits:
Object show all
Extended by:
Monad, Monoid
Defined in:
lib/fr/maybe.rb

Direct Known Subclasses

None_, Some

Defined Under Namespace

Classes: None_, Some

Constant Summary collapse

None =

Singleton instance

None_.new

Class Method Summary collapse

Methods included from Monoid

filter, guard, sum

Methods included from Monad

applyM, composeM, filterM, foldM, forM, join, liftM, mapM, sequence, unlessM, whenM, zipM

Methods included from Functor

#void

Class Method Details

.bind(x, &f) ⇒ Object



19
20
21
# File 'lib/fr/monad/maybe.rb', line 19

def bind(x, &f)
  x.fold(x, &f)
end

.plus(a, b) ⇒ Object

Maybe a -> Maybe a -> Maybe a



11
12
13
# File 'lib/fr/monoid/maybe.rb', line 11

def plus(a, b)
  (a.none?) ? b : a
end

.run(computation) ⇒ Object

Evaluators



8
9
10
# File 'lib/fr/monad/maybe.rb', line 8

def run(computation)
  computation
end

.unit(value) ⇒ Object

Combinators



15
16
17
# File 'lib/fr/monad/maybe.rb', line 15

def unit(value)
  Maybe::Some.new(value)
end

.zeroObject

Maybe a



6
7
8
# File 'lib/fr/monoid/maybe.rb', line 6

def zero
  Maybe::None
end