Class: Fear::Success

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

Instance Method Summary collapse

Methods included from Try

#any?, #each, #get_or_else, #include?, #match, matcher, #to_option

Constructor Details

#initialize(value) ⇒ Success

Returns a new instance of Success.

Parameters:

  • (any)


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

def initialize(value)
  @value = value
end

Instance Method Details

#==(other) ⇒ Boolean

Parameters:

  • other (Any)

Returns:

  • (Boolean)


90
91
92
# File 'lib/fear/success.rb', line 90

def ==(other)
  other.is_a?(Success) && value == other.value
end

#deconstruct<any>

Returns:

  • (<any>)


103
104
105
# File 'lib/fear/success.rb', line 103

def deconstruct
  [value]
end

#failure?false

Returns:

  • (false)


28
29
30
# File 'lib/fear/success.rb', line 28

def failure?
  false
end

#flat_mapTry

Returns:



77
78
79
80
81
# File 'lib/fear/success.rb', line 77

def flat_map
  super
rescue StandardError => error
  Failure.new(error)
end

#flattenTry

Returns:



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

def flatten
  if value.is_a?(Try)
    value.flatten
  else
    self
  end
end

#getany

Returns:

  • (any)


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

def get
  @value
end

#inspectString Also known as: to_s

Returns:

  • (String)


95
96
97
# File 'lib/fear/success.rb', line 95

def inspect
  "#<Fear::Success value=#{value.inspect}>"
end

#mapTry

Returns:



70
71
72
73
74
# File 'lib/fear/success.rb', line 70

def map
  super
rescue StandardError => error
  Failure.new(error)
end

#or_elseSuccess

Returns:



33
34
35
# File 'lib/fear/success.rb', line 33

def or_else
  self
end

#recoverSuccess

Returns:



65
66
67
# File 'lib/fear/success.rb', line 65

def recover
  self
end

#recover_withSuccess

Returns:



60
61
62
# File 'lib/fear/success.rb', line 60

def recover_with
  self
end

#select {|value| ... } ⇒ Try

Yield Parameters:

  • value (any)

Yield Returns:

  • (Boolean)

Returns:



49
50
51
52
53
54
55
56
57
# File 'lib/fear/success.rb', line 49

def select
  if yield(value)
    self
  else
    raise NoSuchElementError, "Predicate does not hold for `#{value}`"
  end
rescue StandardError => error
  Failure.new(error)
end

#success?Boolean

Returns:

  • (Boolean)


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

def success?
  true
end

#to_eitherRight

Returns:



84
85
86
# File 'lib/fear/success.rb', line 84

def to_either
  Right.new(value)
end