I really dig the succinctness of your folding solutions.

On Nov 27, 5:52 pm, rob levy <r.p.l...@gmail.com> wrote:
> fwiw my folding solution above yields the expected result.
>
>
>
>
>
>
>
> On Sat, Nov 27, 2010 at 7:07 PM, Benny Tsai <benny.t...@gmail.com> wrote:
> > > Subvec, however, isn't lazy.
>
> > That's true.  I just realized there's another problem with my approach
> > as well: it does not preserve elements before the first true index.
>
> > user=> (partition-when true? [false true])
> > ([true])
>
> > When the result should probably be:
>
> > user=> (partition-when true? [false true])
> > ((false) (true))
>
> > On Nov 27, 2:05 pm, Ken Wesson <kwess...@gmail.com> wrote:
> > > Subvec, however, isn't lazy. This is:
>
> > > (defn split-when [pred coll]
> > >   (let [ipred (complement pred)
> > >         bits (iterate
> > >                (fn [[out coll]]
> > >                  (let [[a b] (split-with ipred (rest coll))]
> > >                    [(cons (first coll) a) b]))
> > >                [nil coll])]
> > >     (map #(first (first %))
> > >       (take-while #(seq (second (second %))) (map vector (rest bits)
> > bits)))))
>
> > > user=> (take 10 (split-when #(= 0 (rem % 3)) (iterate inc 1)))
> > > ((1 2)
> > >  (3 4 5)
> > >  (6 7 8)
> > >  (9 10 11)
> > >  (12 13 14)
> > >  (15 16 17)
> > >  (18 19 20)
> > >  (21 22 23)
> > >  (24 25 26)
> > >  (27 28 29))
>
> > --
> > 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<clojure%2bunsubscr...@googlegroups.com 
> > >
> > For more options, visit this group at
> >http://groups.google.com/group/clojure?hl=en

-- 
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

Reply via email to