feat(utils): add generic FUNCTIONALIZE to turn values into functions

This commit is contained in:
Edward
2020-12-30 22:03:56 -08:00
parent 1310d70f9c
commit 07b0c02806
3 changed files with 21 additions and 3 deletions

View File

@ -7,6 +7,23 @@
data-lens:compress-runs data-lens:combine-matching-lists
data-lens:juxt data-lens:element data-lens:sorted))
(defgeneric functionalize (it)
(:method ((it hash-table))
(lambda (key &optional default)
(gethash key it default)))
(:method ((it vector))
(lambda (idx &optional default)
(let ((present-p (and (>= idx 0)
(< idx (length it)))))
(values (if present-p
(aref it idx)
default)
present-p))))
(:method ((it symbol))
(fdefinition it))
(:method ((it function))
it))
;;; TODO: consider making this wrap defalias?
(defmacro shortcut (name function &body bound-args)
`(eval-when (:load-toplevel :compile-toplevel :execute)