If we use the cat
transducer instead of calling (concat p pad)
, the code is much faster:
(defn partitionv [n step pad coll]
(lazy-seq
(when-let [s (seq coll)]
(let [p (into [] (take n) s)]
(if (= n (count p))
(cons p (partitionv n step pad (nthrest s step)))
(list (into [] (take n) (concat p pad))))))))
can be changed to
(defn partitionv2 [n step pad coll]
(lazy-seq
(when-let [s (seq coll)]
(let [p (into [] (take n) s)]
(if (= n (count p))
(cons p (partitionv n step pad (nthrest s step)))
(list (into [] (comp cat (take n)) [p pad])))))))