(map vector [1 2 3] [4 5])
will give:
([1 4] [2 5])
Here 3 is discarded.
What if I want to pad those too short seqs to the largest length automatically?
e.g. What's the idiomatic way if I want to get
([1 4] [2 5] [3 nil])
(defn map-all [f & colls]
(lazy-seq
(when (some seq colls)
(cons (apply f (map first colls))
(apply map-all f (map rest colls))))))
(map-all vector [1 2 3] [4 5])
;=> ([1 4] [2 5] [3 nil])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With