Thanks for the replies guys - has given me things to mull over.
On Thursday, 10 May 2012 22:11:18 UTC+1, Ant wrote:
>
> Hi all,
>
> I am battering my head against the following problem which I'm sure is
> straightforward if only I knew how. I want to partition the following
> list:
>
> '("aa12
I think you'd just have to do it manually with a reduce
Something like this should work.
(defn foldfn [i n]
(let [result (first i)
current (second i)]
(if (re-matches #"^(\w)\1.*" n)
(if (= [] current)
[result [n]]
[(conj result current) [n]])
[result (co
On May 10, 3:19 pm, Jack Moffitt wrote:
> > (when-let [s (seq coll)]
> > (let [run (cons (first s) (take-while #(not= value (f %)) (next
> > s)))]
> > (cons run (partition-when f value (seq (drop (count run) s
> > )
> > )
> > )
> > )
> ...
> > What test?
>
> (seq coll) i
https://github.com/flatland/useful/blob/develop/src/useful/seq.clj#L189
is a more general version of partition-by, which can easily handle
your requirements.
On May 10, 2:11 pm, Ant wrote:
> Hi all,
>
> I am battering my head against the following problem which I'm sure is
> straightforward if on
(seq coll) is the test, if the collection is empty seq returns nil, hence
nothing gets done
in the (let ...) form.
Luc
> After posting, I had the idea of checking out the source for partition-
> by, and solved the problem:
>
> (defn partition-when
> "Applies f to each value in coll, splittin
> (when-let [s (seq coll)]
> (let [run (cons (first s) (take-while #(not= value (f %)) (next
> s)))]
> (cons run (partition-when f value (seq (drop (count run) s
> )
> )
> )
> )
...
> What test?
(seq coll) is the test here. when-let (and if-let, etc) bind only when
the r
After posting, I had the idea of checking out the source for partition-
by, and solved the problem:
(defn partition-when
"Applies f to each value in coll, splitting it each time f returns
the specified value. Returns a lazy seq of partitions."
[f value coll]
(lazy-seq
(when-let [s (s