Skip to content

Instantly share code, notes, and snippets.

@carld
Created November 2, 2017 01:28
Show Gist options
  • Save carld/502e0527ac7211b1d81d80fd4ab68714 to your computer and use it in GitHub Desktop.
Save carld/502e0527ac7211b1d81d80fd4ab68714 to your computer and use it in GitHub Desktop.
break out of reduce
run = ->(a,v) { a.reduce(v){|x,y| break unless y.call(v); x } }
run.call [
->(v) { puts "Hello"; true },
->(v) { puts "World"; false },
->(v) { puts "!"; true }
], 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment