On 29 March 2012 21:41, Cedric Greevey cgree...@gmail.com wrote:
On Thu, Mar 29, 2012 at 4:18 PM, David Jagoe davidja...@gmail.com wrote:
Given a sequence like this: [1 2 1 2 1 1 2 1 2 2 2]
partition it to get this: [(1 2) (1 2) (1) (1 2) (1 2) (2) (2)]
!
(defn partition-distinct [s
) (2) (2)]
!
(defn partition-distinct [s]
(lazy-seq
(loop [seen #{} s (seq s) part []]
(if s
(let [[f r] s]
(if (seen f)
(cons (seq part) (partition-distinct s))
(recur (conj seen f) r (conj part f
(if-let [part (seq part
---start-8---
(defn partition-distinct [c]
(reduce #(if (.contains (last %1) %2)
(conj %1 [%2])
(conj (subvec %1 0 (dec (count %1)))
(conj (last %1) %2)))
[[]] (vec c)))
--8---cut here---end
Hi all,
I'm sure I'm missing a really simple way of doing this!
Given a sequence like this: [1 2 1 2 1 1 2 1 2 2 2]
partition it to get this: [(1 2) (1 2) (1) (1 2) (1 2) (2) (2)]
I've been trying to write something generic like partition-by because the
values are maps. Also I want to be able
generic like partition-by because the
values are maps. Also I want to be able to deal with more than 2 distinct
values.
Thanks!
(defn partition-distinct [s]
(lazy-seq
(loop [seen #{} s (seq s) part []]
(if s
(let [[f r] s]
(if (seen f)
(cons (seq part
Yeah I don't like that either. Consider (comp vals (partial group-by
identity)).
On 2012-03-29 16:18 , David Jagoe davidja...@gmail.com wrote:
Hi all,
I'm sure I'm missing a really simple way of doing this!
Given a sequence like this: [1 2 1 2 1 1 2 1 2 2 2]
partition it to get this: [(1 2) (1
Meh. Half-assed (mis)reading. Sorry. -Martin
On 2012-03-29 16:23 , Weber, Martin S martin.we...@nist.gov wrote:
Yeah I don't like that either. Consider (comp vals (partial group-by
identity)).
On 2012-03-29 16:18 , David Jagoe davidja...@gmail.com wrote:
Hi all,
I'm sure I'm missing a really