aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Petton2015-06-21 20:25:28 +0200
committerNicolas Petton2015-06-21 20:26:52 +0200
commita94202b78a8a1ecbb623e76f7feeb3bffc954f12 (patch)
treec00010af62f2a83955e6561a4831c86f671fb0c5
parent3be98ca53b5de3d6442c9318663a8f3cb4dbfed0 (diff)
downloademacs-a94202b78a8a1ecbb623e76f7feeb3bffc954f12.tar.gz
emacs-a94202b78a8a1ecbb623e76f7feeb3bffc954f12.zip
Reuse `alist-get' in map.el
* lisp/emacs-lisp/map.el (map-elt): Use `alist-get' to retrieve alist elements.
-rw-r--r--lisp/emacs-lisp/map.el12
1 files changed, 2 insertions, 10 deletions
diff --git a/lisp/emacs-lisp/map.el b/lisp/emacs-lisp/map.el
index f5a9fd9ee12..1d8a3126bba 100644
--- a/lisp/emacs-lisp/map.el
+++ b/lisp/emacs-lisp/map.el
@@ -106,11 +106,11 @@ form.
106 "Perform a lookup in MAP of KEY and return its associated value. 106 "Perform a lookup in MAP of KEY and return its associated value.
107If KEY is not found, return DEFAULT which defaults to nil. 107If KEY is not found, return DEFAULT which defaults to nil.
108 108
109If MAP is a list, `equal' is used to lookup KEY. 109If MAP is a list, `eql' is used to lookup KEY.
110 110
111MAP can be a list, hash-table or array." 111MAP can be a list, hash-table or array."
112 (map--dispatch map 112 (map--dispatch map
113 :list (map--elt-list map key default) 113 :list (alist-get key map default)
114 :hash-table (gethash key map default) 114 :hash-table (gethash key map default)
115 :array (map--elt-array map key default))) 115 :array (map--elt-array map key default)))
116 116
@@ -324,14 +324,6 @@ MAP can be a list, hash-table or array."
324 (setq index (1+ index)))) 324 (setq index (1+ index))))
325 map))) 325 map)))
326 326
327(defun map--elt-list (map key &optional default)
328 "Lookup, in the list MAP, the value associated with KEY and return it.
329If KEY is not found, return DEFAULT which defaults to nil."
330 (let ((pair (assoc key map)))
331 (if pair
332 (cdr pair)
333 default)))
334
335(defun map--elt-array (map key &optional default) 327(defun map--elt-array (map key &optional default)
336 "Return the element of the array MAP at the index KEY. 328 "Return the element of the array MAP at the index KEY.
337If KEY is not found, return DEFAULT which defaults to nil." 329If KEY is not found, return DEFAULT which defaults to nil."