Created
December 16, 2016 03:06
-
-
Save safiire/db83f2194add8b04304a396c1e221dc5 to your computer and use it in GitHub Desktop.
Kleisli Gem is pretty awesome
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'kleisli' | |
def do_lots(count) | |
(0..count).reduce(0){|sum, value| sum + value } | |
end | |
future = Future(100000000) >-> value { | |
Future { | |
do_lots(value.call) | |
} >-> big_sum { | |
Future{ big_sum.call } | |
} | |
} | |
puts "I'm doing other stuff." | |
puts "Oh, let's also add 7" | |
future2 = future >-> value { | |
Future{ value.call + 7 } | |
} | |
puts future2.await | |
# => I'm doing other stuff. | |
# => Oh, let's also add 7 | |
# => 5000000050000007 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment