Class: Fear::Right

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

Instance Method Summary collapse

Methods included from Either

#any?, #each, #flat_map, #get_or_else, #include?, #initialize, #map, #match, matcher, #or_else, #to_option

Instance Method Details

#join_leftself

Returns:

  • (self)


72
73
74
# File 'lib/fear/right.rb', line 72

def join_left
  self
end

#join_rightEither

Returns:

Raises:

  • (TypeError)


65
66
67
68
69
# File 'lib/fear/right.rb', line 65

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

#left?false Also known as: failure?

Returns:

  • (false)


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

def left?
  false
end

#reduce(_reduce_left, reduce_right) ⇒ any

Parameters:

  • reduce_right (Proc)

Returns:

  • (any)


59
60
61
# File 'lib/fear/right.rb', line 59

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

#rejectEither

Returns:



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

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

#right?true Also known as: success?

Returns:

  • (true)


13
14
15
# File 'lib/fear/right.rb', line 13

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.



8
9
10
# File 'lib/fear/right.rb', line 8

def right_value
  value
end

#selectEither

Returns:



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

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

#select_or_else(default) ⇒ Either

Parameters:

  • default (Proc, any)

Returns:



26
27
28
29
30
31
32
# File 'lib/fear/right.rb', line 26

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

#swapLeft

Returns value in ‘Left`.

Returns:

  • (Left)

    value in ‘Left`



53
54
55
# File 'lib/fear/right.rb', line 53

def swap
  Left.new(value)
end