Class: ReSorcery::Maybe::Just
- Inherits:
-
Object
- Object
- ReSorcery::Maybe::Just
- Includes:
- Fielded
- Defined in:
- lib/re_sorcery/maybe/just.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
- #and_then(&block) ⇒ Object
- #as_json ⇒ Object
- #assign(name, &block) ⇒ Object
- #get_or_else ⇒ Object
-
#initialize(value) ⇒ Just
constructor
A new instance of Just.
- #map(&block) ⇒ Object
- #or_else ⇒ Object
Methods included from Fielded
Constructor Details
#initialize(value) ⇒ Just
Returns a new instance of Just.
11 12 13 |
# File 'lib/re_sorcery/maybe/just.rb', line 11 def initialize(value) @value = value end |
Instance Method Details
#==(other) ⇒ Object
38 39 40 |
# File 'lib/re_sorcery/maybe/just.rb', line 38 def ==(other) other.class == Just && other.instance_eval { @value } == @value end |
#and_then(&block) ⇒ Object
15 16 17 |
# File 'lib/re_sorcery/maybe/just.rb', line 15 def and_then(&block) ArgCheck['block', block.call(@value), Just, Nothing] end |
#as_json ⇒ Object
42 43 44 45 46 47 |
# File 'lib/re_sorcery/maybe/just.rb', line 42 def as_json(*) { kind: :just, value: @value, } end |
#assign(name, &block) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/re_sorcery/maybe/just.rb', line 31 def assign(name, &block) raise Error::NonHashAssignError, @value unless @value.is_a?(Hash) ArgCheck['block', block.call(@value), Just, Nothing] .map { |k| @value.merge(name => k) } end |
#get_or_else ⇒ Object
27 28 29 |
# File 'lib/re_sorcery/maybe/just.rb', line 27 def get_or_else @value end |
#map(&block) ⇒ Object
19 20 21 |
# File 'lib/re_sorcery/maybe/just.rb', line 19 def map(&block) Just.new(block.call(@value)) end |
#or_else ⇒ Object
23 24 25 |
# File 'lib/re_sorcery/maybe/just.rb', line 23 def or_else self end |