Class: Deterministic::Either

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

Direct Known Subclasses

Failure, Success

Defined Under Namespace

Classes: AttemptAll

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PatternMatching

#match

Methods included from Monad

#==, #bind, #initialize, #join, #map, #value

Class Method Details

.attempt_all(context = OpenStruct.new, &block) ⇒ Object



4
5
6
# File 'lib/deterministic/either/attempt_all.rb', line 4

def self.attempt_all(context=OpenStruct.new, &block)
  AttemptAll.new(context, &block).call
end

Instance Method Details

#<<(other) ⇒ Object



14
15
16
17
# File 'lib/deterministic/either.rb', line 14

def <<(other)
  return self if failure?
  return other if other.is_a? Either
end

#failure?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/deterministic/either.rb', line 10

def failure?
  is_a? Failure
end

#inspectObject



32
33
34
35
# File 'lib/deterministic/either.rb', line 32

def inspect
  name = self.class.name.split("::")[-1]
  "#{name}(#{value})"
end

#success?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/deterministic/either.rb', line 6

def success?
  is_a? Success
end

#to_json(*args) ⇒ Object



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

def to_json(*args)
  name = self.class.name.split('::')[-1]
  "{\"#{name}\":#{value.to_json(*args)}}"
end

#to_sObject



28
29
30
# File 'lib/deterministic/either.rb', line 28

def to_s
  value.to_s
end