Class: Kind::Maybe::Monad
- Inherits:
-
Object
- Object
- Kind::Maybe::Monad
- Defined in:
- lib/kind/maybe/monad.rb
Defined Under Namespace
Classes: Wrapper
Constant Summary collapse
- Value =
:nodoc:
->(arg) { arg.kind_of?(Maybe::Monad) ? arg.value : arg }
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #check(&fn) ⇒ Object (also: #accept, #reject)
- #dig(*keys) ⇒ Object
-
#initialize(value) ⇒ Monad
constructor
A new instance of Monad.
- #map(&fn) ⇒ Object (also: #map!, #then, #then!, #and_then)
- #maybe?(matcher) ⇒ Boolean
- #none? ⇒ Boolean
- #on {|monad| ... } ⇒ Object
- #on_none(matcher = UNDEFINED) {|value| ... } ⇒ Object
- #on_some(matcher = UNDEFINED) {|value| ... } ⇒ Object
- #presence ⇒ Object
- #some? ⇒ Boolean
- #try(_method_name = UNDEFINED, &block) ⇒ Object (also: #try!)
- #value_or(_method_name = UNDEFINED, &block) ⇒ Object
Constructor Details
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
8 9 10 |
# File 'lib/kind/maybe/monad.rb', line 8 def value @value end |
Instance Method Details
#check(&fn) ⇒ Object Also known as: accept, reject
36 37 38 |
# File 'lib/kind/maybe/monad.rb', line 36 def check(&fn) raise NotImplementedError end |
#dig(*keys) ⇒ Object
49 50 51 |
# File 'lib/kind/maybe/monad.rb', line 49 def dig(*keys) raise NotImplementedError end |
#map(&fn) ⇒ Object Also known as: map!, then, then!, and_then
26 27 28 |
# File 'lib/kind/maybe/monad.rb', line 26 def map(&fn) raise NotImplementedError end |
#maybe?(matcher) ⇒ Boolean
77 78 79 |
# File 'lib/kind/maybe/monad.rb', line 77 def maybe?(matcher) UNDEFINED == matcher || matcher === value end |
#none? ⇒ Boolean
20 21 22 |
# File 'lib/kind/maybe/monad.rb', line 20 def none? raise NotImplementedError end |
#on {|monad| ... } ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/kind/maybe/monad.rb', line 57 def on monad = Wrapper.new(self) yield(monad) monad.output end |
#on_none(matcher = UNDEFINED) {|value| ... } ⇒ Object
71 72 73 74 75 |
# File 'lib/kind/maybe/monad.rb', line 71 def on_none(matcher = UNDEFINED) yield(value) if none? && maybe?(matcher) self end |
#on_some(matcher = UNDEFINED) {|value| ... } ⇒ Object
65 66 67 68 69 |
# File 'lib/kind/maybe/monad.rb', line 65 def on_some(matcher = UNDEFINED) yield(value) if some? && maybe?(matcher) self end |
#presence ⇒ Object
53 54 55 |
# File 'lib/kind/maybe/monad.rb', line 53 def presence raise NotImplementedError end |
#try(_method_name = UNDEFINED, &block) ⇒ Object Also known as: try!
43 44 45 |
# File 'lib/kind/maybe/monad.rb', line 43 def try(_method_name = UNDEFINED, &block) raise NotImplementedError end |
#value_or(_method_name = UNDEFINED, &block) ⇒ Object
16 17 18 |
# File 'lib/kind/maybe/monad.rb', line 16 def value_or(_method_name = UNDEFINED, &block) raise NotImplementedError end |