Class: Ribimaybe::Maybe::Just
- Inherits:
-
Object
- Object
- Ribimaybe::Maybe::Just
- Includes:
- Contracts
- Defined in:
- lib/ribimaybe.rb,
lib/ribimaybe.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
- #apply(value) ⇒ Object (also: #>>)
- #bind(fn = nil, &block) ⇒ Object (also: #>=)
-
#initialize(value) ⇒ Just
constructor
A new instance of Just.
- #map(&fn) ⇒ Object
- #maybe(_, &fn) ⇒ Object
-
#to_s ⇒ Object
(also: #inspect)
Just string representation.
Constructor Details
#initialize(value) ⇒ Just
Returns a new instance of Just.
67 68 69 |
# File 'lib/ribimaybe.rb', line 67 def initialize(value) @value = value end |
Instance Method Details
#==(other) ⇒ Object
90 91 92 93 94 |
# File 'lib/ribimaybe.rb', line 90 def ==(other) other.maybe(false) do |value| @value == value end end |
#apply(value) ⇒ Object Also known as: >>
141 142 143 |
# File 'lib/ribimaybe.rb', line 141 def apply(value) value.map { |v| @value.curry.(v) } end |
#bind(fn = nil, &block) ⇒ Object Also known as: >=
159 160 161 |
# File 'lib/ribimaybe.rb', line 159 def bind(fn = nil, &block) (fn || block).curry.(@value) end |
#map(&fn) ⇒ Object
124 125 126 |
# File 'lib/ribimaybe.rb', line 124 def map(&fn) Just.new(fn.curry.(@value)) end |
#maybe(_, &fn) ⇒ Object
109 110 111 |
# File 'lib/ribimaybe.rb', line 109 def maybe(_, &fn) fn.curry.(@value) end |
#to_s ⇒ Object Also known as: inspect
Just string representation.
72 73 74 |
# File 'lib/ribimaybe.rb', line 72 def to_s "Just(#{@value.inspect})" end |