(interpose sep)
(interpose sep coll)
Returns a lazy seq of the elements of coll separated by sep.
Returns a stateful transducer when no collection is provided.
Source
(defn interpose
"Returns a lazy seq of the elements of coll separated by sep.
Returns a stateful transducer when no collection is provided."
{:added "1.0"
:static true}
([sep]
(fn [rf]
(let [started (volatile! false)]
(fn
([] (rf))
([result] (rf result))
([result input]
(if @started
(let [sepr (rf result sep)]
(if (reduced? sepr)
sepr
(rf sepr input)))
(do
(vreset! started true)
(rf result input))))))))
([sep coll]
(drop 1 (interleave (repeat sep) coll))))