Class: Deterministic::Either

Inherits:
Object
  • Object
show all
Includes:
Monad
Defined in:
lib/deterministic/either.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#leftObject (readonly)

Returns the value of attribute left.



12
13
14
# File 'lib/deterministic/either.rb', line 12

def left
  @left
end

#rightObject (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

#inspectObject



22
23
24
# File 'lib/deterministic/either.rb', line 22

def inspect
  "Either(left: #{left.inspect}, right: #{right.inspect})"
end