--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
(ns experimental-clojure.congeal-consecutives)
(def v [1 3 4 5 7 9 10 11 12]) (defn congeal-consecutives [coll]
(->> coll (map-indexed (fn [i x] [(- x i) x])) (partition-by first) (mapv (fn [pairs] (mapv second pairs))))) (defn rangify [coll] (mapv (fn [r] (assert (vector? coll)) (let [f (first r) top (peek r)] (if (= f top) (str f) (str f "-" top)))) coll)) (-> v congeal-consecutives rangify)
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
(def data '(1 3 4 5 7 9 10 11 12))
(map #(map last %) (partition-by #(apply - %) (map-indexed vector data))) => ((1) (3 4 5) (7) (9 10 11 12))
regards
PR
--
(defn consecutive? [[x y]] (= (inc x) y))
(def nonconsecutive? (complement consecutive?))
(partition-between nonconsecutive? [1 2 3 4 6 7 9 11 14 15])
;=> ([1 2 3 4] [6 7] [9] [11] [14 15])
(partition-between consecutive? [1 2 3 4 6 7 9 11 14 15])
;=> ([1] [2] [3] [4 6] [7 9 11 14] [15])