Skip to content

Instantly share code, notes, and snippets.

@amalloy
Created September 16, 2011 19:44
Show Gist options
  • Save amalloy/1222948 to your computer and use it in GitHub Desktop.
Save amalloy/1222948 to your computer and use it in GitHub Desktop.
def reductions(f, acc, coll)
F.lazy_seq do
if coll = coll.seq
nacc = f[acc, coll.first]
F.cons(nacc, reductions(f, nacc, coll.rest))
end
end
end
def reductions(f, acc, coll)
F.lazy_loop(acc, coll) do |recur, a, c|
if c = c.seq
nacc = f[acc, c.first]
F.cons(nacc, recur[nacc, c.rest])
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment