A solution based on unfold with the last element read (or initially
nil) and the rest of the list as a seed.

On Thu, Nov 11, 2010 at 12:12 AM, David Jacobs
<develo...@allthingsprogress.com> wrote:
> Thanks for all of the options, and Ken, thanks for the detailed comparison. 
> This will be extremely useful. (I'm trying to port some statistical tests to 
> Clojure for work.)
>
> Best,
> David
>
> On 10 Nov 2010, at 5:13 pm, Alan wrote:
>
>> Juha's is my favorite by a mile. And if you're content with a list of
>> [element, count] pairs, you could do this:
>>
>> (defn seq-ties [coll]
>>  (->> coll (partition-by identity) (filter next) (map (juxt first
>> count)))
>>
>> (seq-ties [1 1 1 1 2 3 3 4 5 7 7])
>> ;==>([1 4] [3 2] [7 2])
>>
>> On Nov 10, 1:27 pm, Juha Arpiainen <jarpi...@gmail.com> wrote:
>>> On Nov 10, 10:28 pm, David Jacobs <develo...@allthingsprogress.com>
>>> wrote:
>>>
>>>> I have a sorted list, and I'd like to derive from that a list
>>>> containing all "ties" in the original.
>>>
>>> One more solution assuming input is sorted:
>>>
>>> (defn seq-ties [coll]
>>>   (mapcat #(cons (first %) %) (keep next (partition-by identity
>>> coll))))
>>>
>>> --
>>> Juha Arpiainen

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to