Add map-padded and sequence-padded#102
Conversation
|
I don't think you need a volatile or anything as complex. We can take the normal (defn map-padded [f val c1 c2 & colls]
(let [step (fn step [cs]
(lazy-seq
(let [ss (map seq cs)]
(when (some identity ss)
(cons (map #(if % (first %) val) ss)
(step (map rest ss)))))))]
(map #(apply f %) (step (conj colls c2 c1)))))Then we just need some more arities for performance in common cases. I've factored out the padded "first" function into an outer (letfn [(first* [s v] (if s (first s) v))]
(defn map-padded
([f val c1 c2]
(lazy-seq
(let [s1 (seq c1) s2 (seq c2)]
(when (or s1 s2)
(cons (f (first* s1 val) (first* s2 val))
(map-padded f val (rest s1) (rest s2)))))))
([f val c1 c2 c3]
(lazy-seq
(let [s1 (seq c1) s2 (seq c2) s3 (seq c3)]
(when (or s1 s2 s3)
(cons (f (first* s1 val) (first* s2 val) (first* s3 val))
(map-padded f val (rest s1) (rest s2) (rest s3)))))))
([f val c1 c2 c3 & colls]
(let [step (fn step [cs]
(lazy-seq
(let [ss (map seq cs)]
(when (some identity ss)
(cons (map #(first* % val) ss)
(step (map rest ss)))))))]
(map #(apply f %) (step (conj colls c3 c2 c1)))))))It looks like the multi-coll version of |
3a6fd9c to
069f24c
Compare
|
I used your implementation except for some small changes, which I left as comments. |
|
I did some performance testing between my initial version and your new version (using |
|
As I said in the issue, |
|
Thanks for doing the benchmarks, and for the performance improvements. I initially thought |
|
I found a tidy solution for |
ecebaa9 to
6f80975
Compare
|
looking at the code again, i should write a test verifying |
6f80975 to
6b27cb1
Compare
|
This all looks good from my side. Is there anything left to add or shall I go ahead and merge? |
6b27cb1 to
b988e8b
Compare
|
The minor-est change, there's no need to call |
A demonstration for #101.