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

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 p

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

partition-when?

2015-08-19 Thread Laurens Van Houtven
red returns true. I found an implementation that used partition-by on the mailing list, but this had some issues: if multiple elems next to each other were true under the pred, it wouldn’t create a new pred for each one. I came up with the following implementation. (defn ^:private partition-w

Re: partition-when

2015-03-05 Thread Steve Miner
what so you don’t even need to call f. Maybe you should for side-effects? (defn partition-when "Applies f to each value in coll, starting a new partition each time f returns a true value. Returns a lazy seq of partitions. Returns a stateful transducer when no collection is pro

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

Re: partition-when

2015-03-04 Thread Ivan L
gt; for some tests I need a function which starts a new partition each time a > predicate returns true, for instance: > > (partition-when > (fn [s] (.startsWith s ">>")) > [">> 1" "2" "3" ">> 4" "5"

partition-when

2015-03-03 Thread 'Frank' via Clojure
Hi all, for some tests I need a function which starts a new partition each time a predicate returns true, for instance: (partition-when (fn [s] (.startsWith s ">>")) [">> 1" "2" "3" ">> 4" "5" "6"]) :=&g

Re: take-to-first & partition-when

2010-03-17 Thread Garth Sheldon-Coulson
artition-by to see if that would help. Turns > out, what I really need are two complementary functions: take-to-first > and partition-when. Take-to-first is similar to take-while, but is > *inclusive* and also inverts the boolean. For example: > > Clojure=> (take-to-first even? [1 1

Re: take-to-first & partition-when

2010-03-17 Thread Per Vognsen
That implementation of partitions feels really low level. If you implement the monadic version of partition-when (which I call partition-where in my own code), it looks as simple as this: (defn partitions [xs] (run-seq (m-partition-where (const [false true]) xs))) -Per On Wed, Mar 17, 2010 at

Re: take-to-first & partition-when

2010-03-17 Thread Greg Fodor
Hey thanks :) These are different than partition-by and take-while. partition-by triggers a new partition when the predicate value *changes*, whereas partition-when triggers a new partition at any point in the sequence where the predicate is true. take-while takes all the items up to the point in

Re: take-to-first & partition-when

2010-03-17 Thread Sean Devlin
ems from coll up to >   and including the point at which it (pred item) returns true. >   pred must be free of side-effects." >   [pred coll] >   (lazy-seq >    (when-let [s (seq coll)] >        (if-not (pred (first s)) >          (cons (first s) (take-to-first pred (res

Re: take-to-first & partition-when

2010-03-16 Thread Greg Fodor
azy-seq (when-let [s (seq coll)] (if-not (pred (first s)) (cons (first s) (take-to-first pred (rest s))) (list (first s)) (defn partition-when "Applies f to each value in coll, splitting it each time f returns true. Returns a lazy seq of lazy seqs." [

take-to-first & partition-when

2010-03-15 Thread Greg Fodor
two complementary functions: take-to-first and partition-when. Take-to-first is similar to take-while, but is *inclusive* and also inverts the boolean. For example: Clojure=> (take-to-first even? [1 1 1 1]) (1 1 1 1) Clojure=> (take-to-first even? [1 1 1 1 2 3 3 3]) (1 1 1 1 2) Clojure=>