Class: RFunk::Either

Inherits:
Object
  • Object
show all
Defined in:
lib/rfunk/either/either.rb

Direct Known Subclasses

Failure, Success

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Either

Returns a new instance of Either.


3
4
5
# File 'lib/rfunk/either/either.rb', line 3

def initialize(value)
  @value = value
end

Instance Method Details

#==(other) ⇒ Object


18
19
20
# File 'lib/rfunk/either/either.rb', line 18

def ==(other)
  other.result == result
end

#resultObject Also known as: identity


7
8
9
10
11
12
13
14
# File 'lib/rfunk/either/either.rb', line 7

def result
  case value
  when RFunk::Some, RFunk::None
    value
  else
    RFunk.option(value)
  end
end