Function: map-apply

map-apply is a byte-compiled function defined in map.el.gz.

Signature

(map-apply FUNCTION MAP)

Documentation

Apply FUNCTION to each element of MAP and return the result as a list.

FUNCTION is called with two arguments, the key of an element and its value. The default implementation delegates to map-do.

Other relevant functions are documented in the map group.

Shortdoc

;; map
(map-apply #'+ (list '(1 . 2) '(3 . 4)))
    => (3 7)

Implementations

(map-apply FUNCTION (MAP array)) in `map.el'.

Implementation of `map-apply' for maps that are arrays. In a map that is an array, the keys are the slot indices, and slot contents are the values. FUNCTION will be called for each element of MAP with the index of the element and the element itself as arguments.

(map-apply FUNCTION (MAP hash-table)) in `map.el'.

Implementation of `map-apply' for maps that are hash-tables. Calls `maphash', which will call FUNCTION for each element in MAP, passing the element's key and its value as arguments of FUNCTION.

(map-apply FUNCTION (MAP list)) in `map.el'.

Implementation of `map-apply' for maps that are plists or alists. In a map that is a plist, property names are the keys, and the corresponding property values are the values of those keys. In a map that is an alist, the `car' of each cons cell is the key and the `cdr' is the value. Calls `mapcar', which will call FUNCTION for each element in MAP, passing the element's key and its value as arguments of FUNCTION.

(map-apply FUNCTION MAP) in `map.el'.

Undocumented

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/map.el.gz
(cl-defgeneric map-apply (function map)
  "Apply FUNCTION to each element of MAP and return the result as a list.
FUNCTION is called with two arguments, the key of an element and its value.
The default implementation delegates to `map-do'."
  (let ((res '()))
    (map-do (lambda (k v) (push (funcall function k v) res)) map)
    (nreverse res)))