Class: Fear::Success

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

Instance Method Summary collapse

Methods included from Try

#any?, #each, #get_or_else, #include?, #to_a, #to_option

Constructor Details

#initialize(value) ⇒ Success



11
12
13
# File 'lib/fear/success.rb', line 11

def initialize(value)
  @value = value
end

Instance Method Details

#failure?false



26
27
28
# File 'lib/fear/success.rb', line 26

def failure?
  false
end

#flat_mapTry



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

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

#flattenTry



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

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

#getany



16
17
18
# File 'lib/fear/success.rb', line 16

def get
  @value
end

#mapTry



68
69
70
71
72
# File 'lib/fear/success.rb', line 68

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

#or_elseSuccess



31
32
33
# File 'lib/fear/success.rb', line 31

def or_else
  self
end

#recoverSuccess



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

def recover
  self
end

#recover_withSuccess



58
59
60
# File 'lib/fear/success.rb', line 58

def recover_with
  self
end

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

Yield Parameters:

  • value (any)

Yield Returns:

  • (Boolean)


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

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

#success?Boolean



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

def success?
  true
end

#to_eitherRight



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

def to_either
  Right.new(value)
end