Skip to content

Instantly share code, notes, and snippets.

@ninjudd
Forked from amalloy/gist:1222948
Created September 16, 2011 20:17
Show Gist options
  • Save ninjudd/1223034 to your computer and use it in GitHub Desktop.
Save ninjudd/1223034 to your computer and use it in GitHub Desktop.
def reductions(*args, &fn)
fn ||= args.shift
Utils.verify_args(args, 0, 1)
acc, coll = (args.empty? ? divide : [args.first, self])
F.lazy_loop(acc, coll) do |recur, acc, coll|
if coll.seq
acc = fn[acc, coll.first]
F.cons(acc, recur[acc, coll.rest])
end
end.conj(acc)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment