Class: Kleisli::Future
Class Method Summary collapse
Instance Method Summary collapse
- #>(f) ⇒ Object
- #await ⇒ Object
- #fmap(&f) ⇒ Object
-
#initialize(t) ⇒ Future
constructor
A new instance of Future.
Methods inherited from Monad
Constructor Details
#initialize(t) ⇒ Future
Returns a new instance of Future.
13 14 15 |
# File 'lib/kleisli/future.rb', line 13 def initialize(t) @t = t end |
Class Method Details
.lift(v = nil, &block) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/kleisli/future.rb', line 5 def self.lift(v=nil, &block) if block new(Thread.new(&block)) else new(Thread.new { v }) end end |
Instance Method Details
#>(f) ⇒ Object
17 18 19 |
# File 'lib/kleisli/future.rb', line 17 def >(f) f.call(-> { await }) end |
#await ⇒ Object
25 26 27 |
# File 'lib/kleisli/future.rb', line 25 def await @t.join.value end |
#fmap(&f) ⇒ Object
21 22 23 |
# File 'lib/kleisli/future.rb', line 21 def fmap(&f) Future.lift(f.call(-> { await })) end |