bobbicodes / bobbi-lisp

Interactive Lisp environment for learning Clojure
https://bobbicodes.github.io/bobbi-lisp/
0 stars 0 forks source link

`map` on arbitrary number of colls #26

Closed bobbicodes closed 11 months ago

bobbicodes commented 11 months ago

Now that map has been implemented as a single multiarity function, it shouldn't be too hard to add an arity that accepts any number of args:

([f c1 c2 c3 & colls]
   (let [step (fn step [cs]
                 (lazy-seq
                  (let [ss (map seq cs)]
                    (when (every? identity ss)
                      (cons (map first ss) (step (map rest ss)))))))]
     (map #(apply f %) (step (conj colls c3 c2 c1)))

The main difference is that our map uses loop, but that might not be a problem since this arity just calls the others.