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 (conj current n)])))
(defn partition-lst
[lst]
(let [reduced (reduce foldfn [[][]] lst)
result (first reduced)
current (second reduced)]
(if (= current [])
result
(conj result current))))
--
Stephen Olsen
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)
On Thursday, May 10, 2012 at 4:11 PM, 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:
>
> '("aa123" "x" "y" "z" "bb123" "ccq23" "3" "yg")
>
> into the following:
>
> (("aa123" "x" "y" "z") ("bb123") ("ccq23" "3" "yg"))
>
> The predicate is:
>
> #(re-matches #"^(\w)\1.*" %)
>
> partition-by doesn't work, since it splits the sequence when the
> result of applying the predicate changes. I want to partition when the
> predicate becomes a particular value.
>
> Any clues on how to accomplish this would be gratefully received!
>
> Thanks,
>
> Anthony.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> (mailto:[email protected])
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> [email protected]
> (mailto:[email protected])
> 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 [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en