Class: Kind::Either::Monad
- Inherits:
-
Object
- Object
- Kind::Either::Monad
- Defined in:
- lib/kind/either/monad.rb
Defined Under Namespace
Classes: Wrapper
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #===(monad) ⇒ Object
- #either?(matcher) ⇒ Boolean
-
#initialize(value) ⇒ Monad
constructor
A new instance of Monad.
- #left? ⇒ Boolean
- #map(&_) ⇒ Object (also: #map!, #then, #then!, #and_then, #and_then!)
- #on {|monad| ... } ⇒ Object
- #on_left(matcher = UNDEFINED) {|value| ... } ⇒ Object
- #on_right(matcher = UNDEFINED) {|value| ... } ⇒ Object
- #right? ⇒ Boolean
- #value_or(_method_name = UNDEFINED, &block) ⇒ Object
Constructor Details
#initialize(value) ⇒ Monad
Returns a new instance of Monad.
11 12 13 |
# File 'lib/kind/either/monad.rb', line 11 def initialize(value) @value = value end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
7 8 9 |
# File 'lib/kind/either/monad.rb', line 7 def value @value end |
Instance Method Details
#===(monad) ⇒ Object
61 62 63 |
# File 'lib/kind/either/monad.rb', line 61 def ===(monad) self.class === monad && self.value === monad.value end |
#either?(matcher) ⇒ Boolean
57 58 59 |
# File 'lib/kind/either/monad.rb', line 57 def either?(matcher) UNDEFINED == matcher || matcher === value end |
#map(&_) ⇒ Object Also known as: map!, then, then!, and_then, and_then!
27 28 29 |
# File 'lib/kind/either/monad.rb', line 27 def map(&_) raise NotImplementedError end |
#on {|monad| ... } ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/kind/either/monad.rb', line 37 def on monad = Wrapper.new(self) yield(monad) monad.output end |
#on_left(matcher = UNDEFINED) {|value| ... } ⇒ Object
51 52 53 54 55 |
# File 'lib/kind/either/monad.rb', line 51 def on_left(matcher = UNDEFINED) yield(value) if left? && either?(matcher) self end |
#on_right(matcher = UNDEFINED) {|value| ... } ⇒ Object
45 46 47 48 49 |
# File 'lib/kind/either/monad.rb', line 45 def on_right(matcher = UNDEFINED) yield(value) if right? && either?(matcher) self end |
#value_or(_method_name = UNDEFINED, &block) ⇒ Object
23 24 25 |
# File 'lib/kind/either/monad.rb', line 23 def value_or(_method_name = UNDEFINED, &block) raise NotImplementedError end |