Skip to content

Instantly share code, notes, and snippets.

(def todo-log (ref []))
(defn save-code-and-snippet [comment code-str]
(dosync (alter todo-log conj [comment code-str])))
(defmacro todo
[comment form]
(do
(save-code-and-snippet comment (str form))
form))
(todo
"I'm not sure this function looks as nice as it could"
(defn converging-seq
"Generates a sequence with terminates when two succent elements
from coll are identical.
(converged-seq [1 2 3 4 4 5 6]) => [1 2 3 4]"
[coll]
(cons
(first coll)
(map second
(defn converging-seq
[coll]
(for [[x y] (partition 2 1 (cons ::not-an-element coll)) :while (not (= x y))] y))
(defn converging-seq2
[[x y & tl]]
(cond (nil? x) []
(nil? y) [x]
(= x y) [x]
:else (lazy-seq (cons x (converging-seq2 (cons y tl))))))
(defn converging-seq
"Generates a sequence with terminates when two successive elements
from coll are identical.
(converged-seq [1 2 3 4 4 5 6]) => [1 2 3 4]"
[coll]
(cons
(first coll)
(map second
(take-while (fn [[prev curr]] (not (= prev curr)))
(partition 2 1 coll)))))
(defn foo [bar] (:baz bar))