Wednesday, September 30, 2009

Short circuiting reductions

Sometimes reduce needs to short circuit


(defn reducer
  "Returns a reduction closure the terminates when pred is false. Applies f to the last value that returns true. f defaults to identity if not provided. Behaves like reduce if pred is always true."
  ([pred] (reducer pred identity))
  ([pred f] (do-stuff:TBD))

1 comment:

  1. When you're right folding rather than left folding, this can be done lazily without a separate predicate:

    http://gist.github.com/337568

    ReplyDelete