Class: Kleisli::Try::Success

Inherits:
Kleisli::Try show all
Defined in:
lib/kleisli/try.rb

Instance Attribute Summary

Attributes inherited from Kleisli::Try

#exception, #value

Instance Method Summary collapse

Methods inherited from Kleisli::Try

lift

Methods inherited from Monad

#>>

Constructor Details

#initialize(value) ⇒ Success

Returns a new instance of Success.



15
16
17
# File 'lib/kleisli/try.rb', line 15

def initialize(value)
  @value = value
end

Instance Method Details

#>(f) ⇒ Object



19
20
21
22
23
# File 'lib/kleisli/try.rb', line 19

def >(f)
  f.call(@value)
rescue => e
  Failure.new(e)
end

#fmap(&f) ⇒ Object



25
26
27
# File 'lib/kleisli/try.rb', line 25

def fmap(&f)
  Try { f.call(@value) }
end

#to_eitherObject



33
34
35
# File 'lib/kleisli/try.rb', line 33

def to_either
  Either::Right.new(@value)
end

#to_maybeObject



29
30
31
# File 'lib/kleisli/try.rb', line 29

def to_maybe
  Maybe::Some.new(@value)
end