Re: break-on-gaps - just curious if there is a more idiomatic way to do this

2011-10-03 Thread Thierry Pirot
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

Re: break-on-gaps - just curious if there is a more idiomatic way to do this

2011-09-29 Thread qhfgva
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

Re: break-on-gaps - just curious if there is a more idiomatic way to do this

2011-09-29 Thread qhfgva
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

Re: break-on-gaps - just curious if there is a more idiomatic way to do this

2011-09-28 Thread Alan Malloy
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)

Re: break-on-gaps - just curious if there is a more idiomatic way to do this

2011-09-28 Thread Nathan Sorenson
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))

break-on-gaps - just curious if there is a more idiomatic way to do this

2011-09-28 Thread qhfgva
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