diff options
| -rw-r--r-- | lisp/emacs-lisp/map.el | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/lisp/emacs-lisp/map.el b/lisp/emacs-lisp/map.el index 4b53524d728..ff0dc120c8a 100644 --- a/lisp/emacs-lisp/map.el +++ b/lisp/emacs-lisp/map.el | |||
| @@ -76,7 +76,7 @@ If MAP is an array, store nil at the index KEY." | |||
| 76 | :array (map--delete-array m ,key)))) | 76 | :array (map--delete-array m ,key)))) |
| 77 | 77 | ||
| 78 | (defun map-nested-elt (map keys &optional default) | 78 | (defun map-nested-elt (map keys &optional default) |
| 79 | "Travserse MAP using KEYS and return the looked up value or DEFAULT if nil. | 79 | "Traverse MAP using KEYS and return the looked up value or DEFAULT if nil. |
| 80 | Map can be a nested map composed of alists, hash-tables and arrays." | 80 | Map can be a nested map composed of alists, hash-tables and arrays." |
| 81 | (or (seq-reduce (lambda (acc key) | 81 | (or (seq-reduce (lambda (acc key) |
| 82 | (when (map-p acc) | 82 | (when (map-p acc) |
| @@ -109,7 +109,7 @@ Map can be a nested map composed of alists, hash-tables and arrays." | |||
| 109 | :array (seq-copy map))) | 109 | :array (seq-copy map))) |
| 110 | 110 | ||
| 111 | (defun map-apply (function map) | 111 | (defun map-apply (function map) |
| 112 | "Return the result of applying FUNCTION to each element of MAP. | 112 | "Apply FUNCTION to each element of MAP and return the result as a list. |
| 113 | FUNCTION is called with two arguments, the key and the value." | 113 | FUNCTION is called with two arguments, the key and the value." |
| 114 | (funcall (map--dispatch map | 114 | (funcall (map--dispatch map |
| 115 | :list #'map--apply-alist | 115 | :list #'map--apply-alist |
| @@ -131,7 +131,7 @@ FUNCTION is called with two arguments, the key and the value." | |||
| 131 | map)) | 131 | map)) |
| 132 | 132 | ||
| 133 | (defun map-filter (pred map) | 133 | (defun map-filter (pred map) |
| 134 | "Return an alist of the key/val pairs of which (PRED key val) is non-nil in MAP." | 134 | "Return an alist of the key/val pairs for which (PRED key val) is non-nil in MAP." |
| 135 | (delq nil (map-apply (lambda (key val) | 135 | (delq nil (map-apply (lambda (key val) |
| 136 | (if (funcall pred key val) | 136 | (if (funcall pred key val) |
| 137 | (cons key val) | 137 | (cons key val) |
| @@ -139,7 +139,7 @@ FUNCTION is called with two arguments, the key and the value." | |||
| 139 | map))) | 139 | map))) |
| 140 | 140 | ||
| 141 | (defun map-remove (pred map) | 141 | (defun map-remove (pred map) |
| 142 | "Return an alist of the key/val pairs of which (PRED key val) is nil in MAP." | 142 | "Return an alist of the key/val pairs for which (PRED key val) is nil in MAP." |
| 143 | (map-filter (lambda (key val) (not (funcall pred key val))) | 143 | (map-filter (lambda (key val) (not (funcall pred key val))) |
| 144 | map)) | 144 | map)) |
| 145 | 145 | ||
| @@ -150,18 +150,15 @@ FUNCTION is called with two arguments, the key and the value." | |||
| 150 | (arrayp map))) | 150 | (arrayp map))) |
| 151 | 151 | ||
| 152 | (defun map-empty-p (map) | 152 | (defun map-empty-p (map) |
| 153 | "Return non-nil is MAP is empty. | ||
| 154 | MAP can be a list, hash-table or array." | ||
| 155 | (null (map-keys map))) | 153 | (null (map-keys map))) |
| 156 | 154 | ||
| 157 | (defun map-contains-key-p (map key &optional testfn) | 155 | (defun map-contains-key-p (map key &optional testfn) |
| 158 | "Return non-nil if MAP contain the key KEY, nil otherwise. | 156 | "Return non-nil if MAP contain the key KEY, nil otherwise. |
| 159 | Equality is defined by TESTFN if non-nil or by `equal' if nil. | 157 | Equality is defined by TESTFN if non-nil or by `equal' if nil." |
| 160 | MAP can be a list, hash-table or array." | ||
| 161 | (seq-contains-p (map-keys map) key testfn)) | 158 | (seq-contains-p (map-keys map) key testfn)) |
| 162 | 159 | ||
| 163 | (defun map-some-p (pred map) | 160 | (defun map-some-p (pred map) |
| 164 | "Return any key/value pair for which (PRED key val) is non-nil is MAP." | 161 | "Return a key/value pair for which (PRED key val) is non-nil in MAP." |
| 165 | (catch 'map--break | 162 | (catch 'map--break |
| 166 | (map-apply (lambda (key value) | 163 | (map-apply (lambda (key value) |
| 167 | (when (funcall pred key value) | 164 | (when (funcall pred key value) |