Class: Fr::Either
Defined Under Namespace
Class Method Summary collapse
- .bind(x, &f) ⇒ Object
-
.lefts(es) ⇒ Object
- Either a b
-
-> [a].
-
.partition(es) ⇒ Object
- Either a b
-
-> [a] -> [b].
- .plus(a, b) ⇒ Object
-
.rights(es) ⇒ Object
- Either a b
-
-> [b].
-
.unit(value) ⇒ Object
Combinators.
- .zero ⇒ Object
Methods included from Monoid
Methods included from Monad
applyM, composeM, filterM, foldM, forM, join, liftM, mapM, sequence, unlessM, whenM, zipM
Methods included from Functor
Class Method Details
.bind(x, &f) ⇒ Object
13 14 15 |
# File 'lib/fr/monad/either.rb', line 13 def bind(x, &f) x.fold(lambda{|l| x }, lambda{|r| f.call(r) }) end |
.lefts(es) ⇒ Object
- Either a b
-
-> [a]
7 8 9 10 11 |
# File 'lib/fr/either.rb', line 7 def lefts(es) es.inject([]) do |ls,e| e.fold(lambda{|l| ls.push(l) }, lambda{|_| ls }) end end |
.partition(es) ⇒ Object
- Either a b
-
-> [a] -> [b]
21 22 23 24 25 26 |
# File 'lib/fr/either.rb', line 21 def partition(es) es.inject([[],[]]) do |(ls,rs),e| e.fold(lambda{|l| [ls.push(l), rs] }, lambda{|r| [ls, rs.push(r)] }) end end |
.plus(a, b) ⇒ Object
9 10 11 |
# File 'lib/fr/monoid/either.rb', line 9 def plus(a, b) (a.left?) ? b : a end |
.rights(es) ⇒ Object
- Either a b
-
-> [b]
14 15 16 17 18 |
# File 'lib/fr/either.rb', line 14 def rights(es) es.inject([]) do |rs,e| e.fold(lambda{|_| rs }, lambda{|r| rs.push(r) }) end end |