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