Class: Fear::Left
- Inherits:
-
Object
- Object
- Fear::Left
- Includes:
- Either, RightBiased::Left
- Defined in:
- lib/fear/left.rb
Constant Summary
Constants included from Fear
Error, IllegalStateException, NoSuchElementError, VERSION
Instance Method Summary collapse
-
#detect(default) ⇒ Either
Returns
Leftordefault. -
#join_left ⇒ Either
Joins an
EitherthroughLeft. -
#join_right ⇒ self
Joins an
EitherthroughRight. -
#reduce(reduce_left, _) ⇒ any
Applies
reduce_leftto the value. -
#swap ⇒ Right
Value in
Right.
Methods included from RightBiased::Left
#any?, #each, #flat_map, #get_or_else, #include?, #map, #to_a, #to_option
Methods included from Utils
#assert_arg_or_block!, #assert_type!, #return_or_call_proc
Methods included from RightBiased::Interface
Methods included from Either
#initialize, #left_class, #right_class
Instance Method Details
#detect(default) ⇒ Either
Returns Left or default.
11 12 13 |
# File 'lib/fear/left.rb', line 11 def detect(default) Left.new(Utils.return_or_call_proc(default)) end |
#join_left ⇒ Either
Joins an Either through Left.
This method requires that the left side of this Either is itself an Either type.
This method, and join_right, are analogous to ‘Option#flatten`
46 47 48 49 50 |
# File 'lib/fear/left.rb', line 46 def join_left value.tap do |v| Utils.assert_type!(v, Either) end end |
#join_right ⇒ self
Joins an Either through Right.
32 33 34 |
# File 'lib/fear/left.rb', line 32 def join_right self end |
#reduce(reduce_left, _) ⇒ any
24 25 26 |
# File 'lib/fear/left.rb', line 24 def reduce(reduce_left, _) reduce_left.call(value) end |