Re: partition-when?

2015-08-20 Thread Steve Miner
If you’re interested in a transducer version of partition-when, here’s my code from https://github.com/miner/transmuters ;; collection version by Frank on mailing list ;; SEM added transducer version, adapted from partition-by (defn partition-when "Applies f to each value in coll, starting a

Re: partition-when?

2015-08-20 Thread Laurens Van Houtven
Gorgeous! Thanks, Moe! (Chris says hi back :)) > On Aug 19, 2015, at 7:51 PM, Moe Aboulkheir wrote: > > Laurens, > > I don't think I've encountered an identical function I can point you to, but > here's an alternative implementation: > > (defn partition-when [pred coll] > (lazy-seq >(wh

Re: partition-when?

2015-08-19 Thread Moe Aboulkheir
Laurens, I don't think I've encountered an identical function I can point you to, but here's an alternative implementation: (defn partition-when [pred coll] (lazy-seq (when-let [[h & t] (seq coll)] (let [[run remains] (split-with (complement pred) t)] (cons (cons h run) (partitio

Re: partition-when

2015-03-05 Thread Steve Miner
For the transducer version, I don’t think you need to keep track of the previous value (fval). The decision to start a new partition group depends only on the current item. Here’s my version. (Warning: virtually untested.) I assume that the first item goes into the first partition no matter wha

Re: partition-when

2015-03-05 Thread Andy-
Tried myself and my first transducer for fun: (defn partition-when [f] (fn [rf] (let [a (java.util.ArrayList.) fval (volatile! false)] (fn ([] (rf)) ([result] (let [result (if (.isEmpty a) result

Re: partition-when

2015-03-05 Thread Martin Harrigan
Hi Frank, I use a similar function that combines partition-by and partition-all: (defn partition-when [f coll] (map (partial apply concat) (partition-all 2 (partition-by f coll Martin. On Wed, Mar 4, 2015 at 10:19 PM, Ivan L wrote: > I went though almost the exact same exercise and m

Re: partition-when

2015-03-04 Thread Ivan L
I went though almost the exact same exercise and my code is almost identical to yours. I called it partition-every and I use it a lot. A more determined individual might submit this for inclusion into core! On Tuesday, March 3, 2015 at 2:46:29 PM UTC-5, Frank wrote: > > Hi all, > > for some te