Thank you everyone who responded. After looking over the ideas I chose a
variant on Thomas Mulvaney's suggestion:
(defn consolidate-events
"Return a time series like this `series`, but without those events whose
value is
identical to the value of the preceding event."
[series]
(map last
Oooh, that one is neat.
On Tuesday, 17 May 2016 12:27:29 UTC+1, Thomas Mulvaney wrote:
>
> Rather than writing a new function you could always use something like
> (map first (partition-by :value events)). partition-by will create lists of
> events where consecutive values have not changed. You
On Tuesday, May 17, 2016 at 5:47:06 AM UTC-4, Simon Brooke wrote:
>
> I'm having trouble with writing a function
>
>1. in idiomatic clojure
>2. which doesn't blow the stack
>
> The problem is I have a time series of events e.g.
>
> ({:idhistory 78758272, :timestamp #inst
> "2016-03-31T19:3
Rather than writing a new function you could always use something like (map
first (partition-by :value events)). partition-by will create lists of
events where consecutive values have not changed. You could also assemble a
transducer pipeline using the transducer arities of the functions: `(into
[]
Test passed code, but I don't know about performance.
(defn consolidate-events [series]
(reduce (fn [result cur]
(let [prev (last result)]
(cond
(nil? prev)
(conj result cur)
(= (:value prev) (:value cur))
Hi,
dedupe is almost what you need, but you can just copy the source and modify
it slightly:
(defn dedupe-by
"Similar to dedupe but allows applying a function to the element by which to
dedupe."
([f]
(fn [rf]
(let [pv (volatile! ::none)]
(fn
([] (rf))
([resu
On 17 May 2016, at 10:47, 'Simon Brooke' via Clojure
wrote:
> I'm having trouble with writing a function
> in idiomatic clojure
> which doesn't blow the stack
> The problem is I have a time series of events e.g.
>
> ({:idhistory 78758272, :timestamp #inst
> "2016-03-31T19:34:27.31300-00:00