Class: Deterministic::Either
- Includes:
- Monad
- Defined in:
- lib/deterministic/either.rb
Instance Attribute Summary collapse
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#right ⇒ Object
readonly
Returns the value of attribute right.
Instance Method Summary collapse
- #+(other) ⇒ Object
-
#initialize(left = [], right = []) ⇒ Either
constructor
A new instance of Either.
- #inspect ⇒ Object
Methods included from Monad
#==, #bind, #fmap, #join, #to_s, #value
Constructor Details
#initialize(left = [], right = []) ⇒ Either
Returns a new instance of Either.
8 9 10 |
# File 'lib/deterministic/either.rb', line 8 def initialize(left=[], right=[]) @left, @right = left, right end |
Instance Attribute Details
#left ⇒ Object (readonly)
Returns the value of attribute left.
12 13 14 |
# File 'lib/deterministic/either.rb', line 12 def left @left end |
#right ⇒ Object (readonly)
Returns the value of attribute right.
12 13 14 |
# File 'lib/deterministic/either.rb', line 12 def right @right end |
Instance Method Details
#+(other) ⇒ Object
14 15 16 17 18 |
# File 'lib/deterministic/either.rb', line 14 def +(other) raise Deterministic::Monad::NotMonadError, "Expected an Either, got #{other.class}" unless other.is_a? Either Either.new(left + other.left, right + other.right) end |
#inspect ⇒ Object
22 23 24 |
# File 'lib/deterministic/either.rb', line 22 def inspect "Either(left: #{left.inspect}, right: #{right.inspect})" end |