mirror of
https://github.com/fiddlerwoaroof/data-lens.git
synced 2025-11-08 18:26:32 +00:00
feat: generic lens infrastructure
This commit is contained in:
12
optics.lisp
12
optics.lisp
@ -217,3 +217,15 @@ contain the new value at the location focused by the lens."
|
|||||||
(set 'a-lens 2
|
(set 'a-lens 2
|
||||||
(make-instance 'foo :a 1)))) #|
|
(make-instance 'foo :a 1)))) #|
|
||||||
==> 3 |#)
|
==> 3 |#)
|
||||||
|
|
||||||
|
(defgeneric generic-lens (rec cb loc)
|
||||||
|
(:method ((rec hash-table) cb loc)
|
||||||
|
(funcall (funcall (make-hash-table-lens loc)
|
||||||
|
cb)
|
||||||
|
rec)))
|
||||||
|
|
||||||
|
(defun lens (loc)
|
||||||
|
"A lens for updating a hash-table, discarding previous values"
|
||||||
|
(lambda (cb)
|
||||||
|
(lambda (rec)
|
||||||
|
(generic-lens rec cb loc))))
|
||||||
|
|||||||
Reference in New Issue
Block a user