Return keys from hast tables, plists, and alists
Heime <[email protected]>
| Newsgroups | gmane.emacs.help |
|---|---|
| Message-ID | <-213Trsj1TYfCz1kCvub9-UeDQoeQRHSYF9t8RIt5NrufFgZUQpN7mo4dEX0LeTFBXVHzq_vHT_r9P0gCkmcZNrliznqkRzgd53sfc9uSmg=@protonmail.com> |
This function returns keys from hast tables, plists, and alists.
Should I include anything less or more to it?
(defun aplt-keys (tpal)
"Return keys from ALIST, PLIST, or HASH-TABLE.
INPUT alist, plist, or hash-table"
(cond
;; HASH TABLE
((hash-table-p tpal)
(hash-table-keys tpal))
;; Property List (PLIST)
((and (listp tpal) (cl-evenp (length tpal)) (plistp tpal))
(let (keys)
(while tpal
(push (car tpal) keys)
(setq tpal (cddr tpal)))
(nreverse keys)))
;; Association List (ALIST)
((and (listp tpal) (alistp tpal))
(mapcar #'car tpal))
(t (message "Input Type not supported: %s" (type-of tpal)))))