Hi,

Am 09.11.2009 um 07:33 schrieb Wilson MacGyver:

> I did search in the API docs for both core and contrib, but didn't
> find anything like
> it.
>
> Does Clojure have a function like Haskell's group?
>
> In Haskell,
> Input: group [1,2,2,1,1,1,2,2,2,1]
> Output: [[1],[2,2],[1,1,1],[2,2,2],[1]]

I'm not aware of such a function. There might be something like  
partition-by or so in clojure.contrib.seq-utils. But if not, it's easy  
to roll your own:

(defn group
   [s]
   (lazy-seq
     (when-let [s (seq s)]
       (let [f        (first s)
             [fs & r] (split-with #(= % f) s)]
         (cons fs (group r))))))

Sincerely
Meikel

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to