Class: Fear::Right

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

Instance Method Summary collapse

Methods included from Either

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

Instance Method Details

#join_leftself

Returns:

  • (self)


74
75
76
# File 'lib/fear/right.rb', line 74

def join_left
  self
end

#join_rightEither

Returns:

Raises:

  • (TypeError)


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

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

#left?false Also known as: failure?

Returns:

  • (false)


21
22
23
# File 'lib/fear/right.rb', line 21

def left?
  false
end

#reduce(_reduce_left, reduce_right) ⇒ any

Parameters:

  • reduce_right (Proc)

Returns:

  • (any)


61
62
63
# File 'lib/fear/right.rb', line 61

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

#rejectEither

Returns:



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

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

#right?true Also known as: success?

Returns:

  • (true)


15
16
17
# File 'lib/fear/right.rb', line 15

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.



10
11
12
# File 'lib/fear/right.rb', line 10

def right_value
  value
end

#selectEither

Returns:



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

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

#select_or_else(default) ⇒ Either

Parameters:

  • default (Proc, any)

Returns:



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

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`



55
56
57
# File 'lib/fear/right.rb', line 55

def swap
  Left.new(value)
end