mark-naylor-1701

elisp mapcat

Nov 2nd, 2025 (edited)
1,078
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.63 KB | None | 0 0
  1. ;; This is an elisp verision of the mapcat function found in the core Clojure library.
  2.  
  3. (defun mapcat (f xs &rest xss)
  4.   "Returns the result of applying append to the result of applying mapcar
  5. to f and sequences. Thus function f should return a sequence."
  6.   ;; Make sure all the arguments are sequences.
  7.   (assert
  8.    (and (sequencep xs)
  9.         (cl-every
  10.          (lambda (x) (or (listp x) (vectorp x)))
  11.          xss)))
  12.   ;; Combine the top level sequences into one.
  13.   (apply
  14.    #'append
  15.    ;; Run the supplied function on the sequence(s).
  16.    (apply
  17.     #'cl-mapcar
  18.     f
  19.     ;; Combine the sequences.
  20.     (cons xs xss))))
Advertisement
Add Comment
Please, Sign In to add comment