Module: Mayak::Monads::Try
- Extended by:
- T::Generic, T::Sig
- Included in:
- Failure, Success
- Defined in:
- lib/mayak/monads/try.rb
Defined Under Namespace
Modules: Mixin
Classes: Failure, Success
Constant Summary
collapse
- Value =
type_member(:out)
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.check(value, error, &blk) ⇒ Object
210
211
212
213
214
215
216
|
# File 'lib/mayak/monads/try.rb', line 210
def self.check(value, error, &blk)
if blk.call
Mayak::Monads::Try::Success[T.type_parameter(:Value)].new(value)
else
Mayak::Monads::Try::Failure[T.type_parameter(:Value)].new(error)
end
end
|
.guard(error, &blk) ⇒ Object
219
220
221
|
# File 'lib/mayak/monads/try.rb', line 219
def self.guard(error, &blk)
check(nil, error, &blk)
end
|
.sequence(results) ⇒ Object
193
194
195
196
197
198
199
200
|
# File 'lib/mayak/monads/try.rb', line 193
def self.sequence(results)
init = T.let(Try::Success.new([]), Try[T::Array[T.type_parameter(:Value)]])
results.reduce(init) do |result, element|
result.flat_map do |array|
element.map { |value| array + [value] }
end
end
end
|
Instance Method Details
#as(new_value) ⇒ Object
140
141
142
|
# File 'lib/mayak/monads/try.rb', line 140
def as(new_value)
map { |_| new_value }
end
|
#either(failure_branch, success_branch) ⇒ Object
74
75
|
# File 'lib/mayak/monads/try.rb', line 74
def either(failure_branch, success_branch)
end
|
#failure? ⇒ Boolean
48
49
|
# File 'lib/mayak/monads/try.rb', line 48
def failure?
end
|
#failure_as(new_failure) ⇒ Object
145
146
147
|
# File 'lib/mayak/monads/try.rb', line 145
def failure_as(new_failure)
map_failure { |_| new_failure }
end
|
#failure_or(value) ⇒ Object
61
62
|
# File 'lib/mayak/monads/try.rb', line 61
def failure_or(value)
end
|
#filter_or(error, &blk) ⇒ Object
40
41
|
# File 'lib/mayak/monads/try.rb', line 40
def filter_or(error, &blk)
end
|
#flat_map(&blk) ⇒ Object
32
33
|
# File 'lib/mayak/monads/try.rb', line 32
def flat_map(&blk)
end
|
#flat_map_failure(&blk) ⇒ Object
99
100
|
# File 'lib/mayak/monads/try.rb', line 99
def flat_map_failure(&blk)
end
|
#map(&blk) ⇒ Object
21
22
|
# File 'lib/mayak/monads/try.rb', line 21
def map(&blk)
end
|
#map_failure(&blk) ⇒ Object
90
91
|
# File 'lib/mayak/monads/try.rb', line 90
def map_failure(&blk)
end
|
#recover(value) ⇒ Object
155
156
|
# File 'lib/mayak/monads/try.rb', line 155
def recover(value)
end
|
#recover_on(error_type, &blk) ⇒ Object
176
177
|
# File 'lib/mayak/monads/try.rb', line 176
def recover_on(error_type, &blk)
end
|
#recover_with(&blk) ⇒ Object
164
165
|
# File 'lib/mayak/monads/try.rb', line 164
def recover_with(&blk)
end
|
#recover_with_try(&blk) ⇒ Object
184
185
186
|
# File 'lib/mayak/monads/try.rb', line 184
def recover_with_try(&blk)
flat_map_failure(&blk)
end
|
#success? ⇒ Boolean
44
45
|
# File 'lib/mayak/monads/try.rb', line 44
def success?
end
|
#success_or(value) ⇒ Object
57
58
|
# File 'lib/mayak/monads/try.rb', line 57
def success_or(value)
end
|
#tee(&blk) ⇒ Object
82
83
|
# File 'lib/mayak/monads/try.rb', line 82
def tee(&blk)
end
|
#to_maybe ⇒ Object
112
113
|
# File 'lib/mayak/monads/try.rb', line 112
def to_maybe
end
|
#to_result(&blk) ⇒ Object
108
109
|
# File 'lib/mayak/monads/try.rb', line 108
def to_result(&blk)
end
|