Last active
August 14, 2023 13:31
Revisions
-
johnwalker revised this gist
Nov 7, 2014 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,7 +11,6 @@ (defn rangify [coll] (mapv (fn [r] (let [f (first r) top (peek r)] (if (= f top) -
johnwalker revised this gist
Nov 7, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,7 +11,7 @@ (defn rangify [coll] (mapv (fn [r] (assert (vector? r)) (let [f (first r) top (peek r)] (if (= f top) -
johnwalker created this gist
Nov 7, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ (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)