Skip to content

Instantly share code, notes, and snippets.

@safiire
Created December 16, 2016 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save safiire/db83f2194add8b04304a396c1e221dc5 to your computer and use it in GitHub Desktop.
Save safiire/db83f2194add8b04304a396c1e221dc5 to your computer and use it in GitHub Desktop.
Kleisli Gem is pretty awesome
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