Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; This is an elisp verision of the mapcat function found in the core Clojure library.
- (defun mapcat (f xs &rest xss)
- "Returns the result of applying append to the result of applying mapcar
- to f and sequences. Thus function f should return a sequence."
- ;; Make sure all the arguments are sequences.
- (assert
- (and (sequencep xs)
- (cl-every
- (lambda (x) (or (listp x) (vectorp x)))
- xss)))
- ;; Combine the top level sequences into one.
- (apply
- #'append
- ;; Run the supplied function on the sequence(s).
- (apply
- #'cl-mapcar
- f
- ;; Combine the sequences.
- (cons xs xss))))
Advertisement
Add Comment
Please, Sign In to add comment