Class: Fear::Right

Inherits:
Object
  • Object
show all
Includes:
Either, Fear::RightBiased::Right
Defined in:
lib/fear/right.rb

Constant Summary collapse

EXTRACTOR =
proc do |either|
  if Fear::Right === either
    Fear.some([either.right_value])
  else
    Fear.none
  end
end

Instance Method Summary collapse

Methods included from Fear::RightBiased::Right

#===, #any?, #each, #flat_map, #get_or_else, #include?, included, #map, #or_else, #to_option

Methods included from Either

#==, #any?, #each, #flat_map, #get_or_else, #include?, #initialize, #inspect, #left_class, #map, #match, matcher, #or_else, #right_class, #to_option

Instance Method Details

#join_leftself


82
83
84
# File 'lib/fear/right.rb', line 82

def join_left
  self
end

#join_rightEither

Raises:

  • (TypeError)

75
76
77
78
79
# File 'lib/fear/right.rb', line 75

def join_right
  value.tap do |v|
    Utils.assert_type!(v, Either)
  end
end

#left?false Also known as: failure?


29
30
31
# File 'lib/fear/right.rb', line 29

def left?
  false
end

#reduce(_reduce_left, reduce_right) ⇒ any


69
70
71
# File 'lib/fear/right.rb', line 69

def reduce(_reduce_left, reduce_right)
  reduce_right.(value)
end

#rejectEither


54
55
56
57
58
59
60
# File 'lib/fear/right.rb', line 54

def reject
  if yield(value)
    Left.new(value)
  else
    self
  end
end

#right?true Also known as: success?


23
24
25
# File 'lib/fear/right.rb', line 23

def right?
  true
end

#right_valueObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


18
19
20
# File 'lib/fear/right.rb', line 18

def right_value
  value
end

#selectEither


45
46
47
48
49
50
51
# File 'lib/fear/right.rb', line 45

def select
  if yield(value)
    self
  else
    Left.new(value)
  end
end

#select_or_else(default) ⇒ Either


36
37
38
39
40
41
42
# File 'lib/fear/right.rb', line 36

def select_or_else(default)
  if yield(value)
    self
  else
    Left.new(Utils.return_or_call_proc(default))
  end
end

#swapLeft


63
64
65
# File 'lib/fear/right.rb', line 63

def swap
  Left.new(value)
end