qhfgva, 2011-09-28 20:39 +0200
> I was wondering if there is a more clever/idiomatic way
> to solve this problem.
>
> (defn break-on-gaps [minutes]
> (reduce (fn [acc x]
> (if (empty? acc)
> [[x]]
> (if (= (inc (last (last acc))) x)
> (conj (vec (bu
Nice. Also this makes me think that my clojure intuitions are getting
better.
On Sep 28, 3:07 pm, Alan Malloy wrote:
> I wrote a generalized version of this called partition-between, which
> you can see
> athttps://github.com/flatland/useful/blob/develop/src/useful/seq.clj#L181
> if you're inte
Thanks. That's helps me think about when/how to use lazy-seq
On Sep 28, 2:00 pm, Nathan Sorenson wrote:
> If you were feeling so inclined, you could structure this as a lazy sequence
> (like 'partition' does)
>
> (defn lazy-break
> [coll]
> (letfn [(break-paired [pairs]
> (lazy-s
I wrote a generalized version of this called partition-between, which
you can see at
https://github.com/flatland/useful/blob/develop/src/useful/seq.clj#L181
if you're interested. Using that as a primitive, your break-on-gaps
function is simple:
user> (partition-between (fn [[a b]] (not= a (dec b)
If you were feeling so inclined, you could structure this as a lazy sequence
(like 'partition' does)
(defn lazy-break
[coll]
(letfn [(break-paired [pairs]
(lazy-seq
(when-let [s (seq pairs)]
(let [p (doall (take-while (fn [[a b]] (= (inc a) b)) pairs))
I've been working on problems from "Programming Challenges" (Skiena)
to learn clojure. As part of a problem I developed the following
routine. I sort of scare myself how natural thinking in reduce is
getting, but I was wondering if there is a more clever/idiomatic way
to solve this problem.
(def