mirror of
https://github.com/doomemacs/doomemacs
synced 2025-08-01 12:17:25 -05:00
feat(lib): add doom-plist-{map,map*}
This commit is contained in:
@ -26,6 +26,36 @@
|
|||||||
(cadr val)
|
(cadr val)
|
||||||
nil-value))
|
nil-value))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun doom-plist-map (fn plist)
|
||||||
|
"Map FN on each keyword/value pair in PLIST.
|
||||||
|
|
||||||
|
FN is a function that takes two arguments: a keyword and value, and its return
|
||||||
|
values are accumulated ala `mapcar'."
|
||||||
|
(cl-loop for (key val) on plist by #'cddr
|
||||||
|
while (keywordp key)
|
||||||
|
do (plist-put plist key (funcall fn key val))))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun doom-plist-map* (fn vplist)
|
||||||
|
"Apply FN to each variadic property in VPLIST.
|
||||||
|
|
||||||
|
FN is a variadic function, whose first argument is the keyword and the rest the
|
||||||
|
values that follow (until the next keyword). Its return value is accumulated ala
|
||||||
|
`mapcar'.
|
||||||
|
|
||||||
|
VPLIST is a variadic-property list (a plist whose key may be followed by one or
|
||||||
|
more values)."
|
||||||
|
(let ((vplist (copy-sequence vplist))
|
||||||
|
results)
|
||||||
|
(while vplist
|
||||||
|
(let ((prop (pop vplist))
|
||||||
|
vals)
|
||||||
|
(while (and vplist (not (keywordp (car vplist))))
|
||||||
|
(push (pop vplist) vals))
|
||||||
|
(push (funcall fn prop (nreverse vals)) results)))
|
||||||
|
(nreverse results)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom-plist-merge (from-plist to-plist)
|
(defun doom-plist-merge (from-plist to-plist)
|
||||||
"Non-destructively merge FROM-PLIST onto TO-PLIST"
|
"Non-destructively merge FROM-PLIST onto TO-PLIST"
|
||||||
|
Reference in New Issue
Block a user