mirror of
https://github.com/fiddlerwoaroof/data-lens.git
synced 2025-11-08 18:26:32 +00:00
feat(utils): add generic FUNCTIONALIZE to turn values into functions
This commit is contained in:
17
lens.lisp
17
lens.lisp
@ -7,6 +7,23 @@
|
|||||||
data-lens:compress-runs data-lens:combine-matching-lists
|
data-lens:compress-runs data-lens:combine-matching-lists
|
||||||
data-lens:juxt data-lens:element data-lens:sorted))
|
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?
|
;;; TODO: consider making this wrap defalias?
|
||||||
(defmacro shortcut (name function &body bound-args)
|
(defmacro shortcut (name function &body bound-args)
|
||||||
`(eval-when (:load-toplevel :compile-toplevel :execute)
|
`(eval-when (:load-toplevel :compile-toplevel :execute)
|
||||||
|
|||||||
@ -18,8 +18,7 @@
|
|||||||
#:compress-runs #:combine-matching-lists #:sorted #:applicable-when
|
#:compress-runs #:combine-matching-lists #:sorted #:applicable-when
|
||||||
#:of-length #:of-min-length #:of-max-length #:transform-head
|
#:of-length #:of-min-length #:of-max-length #:transform-head
|
||||||
#:maximizing #:zipping #:applying #:splice-elt #:transform-elt #:denest
|
#:maximizing #:zipping #:applying #:splice-elt #:transform-elt #:denest
|
||||||
#:op #:defalias #:<> #:<>1 #:== #:•
|
#:op #:defalias #:<> #:<>1 #:== #:• #:suffixp #:functionalize))
|
||||||
))
|
|
||||||
|
|
||||||
(defpackage :data-lens.transducers.internals
|
(defpackage :data-lens.transducers.internals
|
||||||
(:use :cl)
|
(:use :cl)
|
||||||
|
|||||||
@ -11,7 +11,9 @@
|
|||||||
(:method ((seq sequence) (func symbol) init)
|
(:method ((seq sequence) (func symbol) init)
|
||||||
(reduce func seq :initial-value init))
|
(reduce func seq :initial-value init))
|
||||||
(:method (seq (func symbol) init)
|
(:method (seq (func symbol) init)
|
||||||
(reduce-generic seq (symbol-function func) init))
|
(reduce-generic seq
|
||||||
|
(symbol-function func)
|
||||||
|
init))
|
||||||
(:method ((seq hash-table) (func function) init)
|
(:method ((seq hash-table) (func function) init)
|
||||||
(let ((acc init))
|
(let ((acc init))
|
||||||
(maphash (lambda (k v)
|
(maphash (lambda (k v)
|
||||||
|
|||||||
Reference in New Issue
Block a user