Class: Fear::Left

Inherits:
Object
  • Object
show all
Includes:
Either, RightBiased::Left
Defined in:
lib/fear/left.rb

Constant Summary

Constants included from Fear

Error, IllegalStateException, NoSuchElementError, VERSION

Instance Method Summary collapse

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

#flat_map, #get_or_else

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_leftEither

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`

Raises:

  • (TypeError)

    if it does not contain Either.



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_rightself

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

#swapRight



17
18
19
# File 'lib/fear/left.rb', line 17

def swap
  Right.new(value)
end