clojure.core/mapcat¶
Returns the result of applying concat to the result of applying map to f and colls. Thus function f should return a collection. Returns a transducer when no collections are provided
Examples¶
Note by reborg¶
;; mapcat always evaluates the first 4 arguments.
(def a (mapcat range (map #(do (print ".") %) (into () (range 10)))))
;; ....
;; it can be solved avoiding 'apply' to handle varargs
(defn mapcat* [f & colls]
(letfn [(step [colls]
(lazy-seq
(when-first [c colls]
(concat c (step (rest colls))))))]
(step (apply map f colls))))
(def a (mapcat* range (map #(do (print ".") %) (into () (range 10)))))
;; nothing prints
See also¶
- clojure.core/map (13)
- clojure.core/concat (7)
- clojure.core/flatten (1)
Content from the matching ClojureDocs page, with authors credited on each contribution.