Rudolf Adamkovič Personal site


Map n-to-m: mapcan function

A higher-order Elisp function that maps n elements to m elements 18:

(mapcan (lambda (x)
          (pcase x
            (10 '(100))       ; map
            (20 '())          ; filter
            (30 '(300 300)))) ; flat-map
        '(10 20 30))
(100 300 300)
(mapcan #'identity '((10) (20) (30))) ; flatten
(10 20 30)

Footnotes

(18)

Accepts lists, vectors, and strings, and always returns a list.


© 2025 Rudolf Adamkovič under GNU General Public License version 3.
Made with Emacs and secret alien technologies of yesteryear.