From f9d091759c9971a3f3c656d0f1ad6d8a0f18a2f8 Mon Sep 17 00:00:00 2001 From: Edward Langley Date: Sat, 28 Jun 2025 14:47:10 -0700 Subject: [PATCH] feat: generic lens infrastructure --- optics.lisp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/optics.lisp b/optics.lisp index 8e9009b..0367eaf 100644 --- a/optics.lisp +++ b/optics.lisp @@ -217,3 +217,15 @@ contain the new value at the location focused by the lens." (set 'a-lens 2 (make-instance 'foo :a 1)))) #| ==> 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))))