Thanks, that was indeed helpful!
On Nov 6, 6:47 pm, Alex Osborne <a...@meshy.org> wrote:
> Alex Osborne wrote:
> > Like Mark's but using split-with instead of split-at:
>
> > (defn partition-when [pred coll]
> > (lazy-seq
> > (when-let [[x & xs] (seq coll)]
> > (let [[xs ys] (split-with (complement pred) xs)]
> > (cons (cons x xs) (partition-when pred ys))))))
>
> Just realised this is almost the same as Warren's -- I had missed
> reading Warren's before posting. Thought it might be helpful if I
> explain the differences:
>
> * lazy-seq on the outside of the conditional. This means the seq is
> fully lazy, so if you never call first/next on it, nothing is ever run.
>
> * As suggested by others complement instead of NOT.
>
> * (when (seq coll) ...) instead of (if (empty? coll) () ...). We can
> simplify things like this as (lazy-seq nil) => () and (seq ()) => nil.
>
> * Using destructuring instead of (first coll) (next coll). Makes it a
> bit shorter and is quite useful if you're going to use the result of
> (first coll) or (next coll) multiple times, but in this case it doesn't
> really matter.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---