Class: Deterministic::Either
Overview
Abstract parent of Success and Failure
Defined Under Namespace
Modules: Chain
Classes: AttemptAll
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Chain
#chain, #try
#match
Methods included from Monad
#==, #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
22
23
24
25
|
# File 'lib/deterministic/either.rb', line 22
def <<(other)
return self if failure?
return other if other.is_a? Either
end
|
#bind(proc = nil, &block) ⇒ Object
8
9
10
11
12
|
# File 'lib/deterministic/either.rb', line 8
def bind(proc=nil, &block)
(proc || block).call(value, self.class).tap do |result|
raise NotMonadError, "Expected #{result.inspect} to be an Either" unless result.is_a? self.class.superclass
end
end
|
#failure? ⇒ Boolean
18
19
20
|
# File 'lib/deterministic/either.rb', line 18
def failure?
is_a? Failure
end
|
36
37
38
39
|
# File 'lib/deterministic/either.rb', line 36
def inspect
name = self.class.name.split("::")[-1]
"#{name}(#{value})"
end
|
#success? ⇒ Boolean
14
15
16
|
# File 'lib/deterministic/either.rb', line 14
def success?
is_a? Success
end
|
32
33
34
|
# File 'lib/deterministic/either.rb', line 32
def to_s
value.to_s
end
|