git.fiddlerwoaroof.com
Browse code

feat: calling and calling*

Edward Langley authored on 15/07/2023 17:27:36
Showing 3 changed files
... ...
@@ -344,6 +344,11 @@
344 344
     `(lambda (,first-arg)
345 345
        (funcall (functionalize ,fun) ,first-arg ,@args))))
346 346
 
347
+(defmacro calling* (fun &rest args)
348
+  (alexandria:with-gensyms (last-arg)
349
+    `(lambda (,last-arg)
350
+       (funcall (functionalize ,fun) ,@args ,last-arg))))
351
+
347 352
 (defmacro applying (fun &rest args)
348 353
   (alexandria:with-gensyms (seq fsym)
349 354
     `(let ((,fsym (functionalize ,fun)))
... ...
@@ -20,7 +20,8 @@
20 20
            #:maximizing #:zipping #:applying #:splice-elt
21 21
            #:transform-elt #:denest #:op #:defalias #:<> #:<>1 #:== #:•
22 22
            #:∘ #:suffixp #:functionalize #:inc #:group-by #:keys
23
-           #:conj #:disj #:delay #:of-type #:transform))
23
+           #:conj #:disj #:delay #:of-type #:transform #:calling*
24
+           #:calling))
24 25
 
25 26
 (defpackage :data-lens.transducers.internals
26 27
   (:use :cl)
... ...
@@ -284,3 +284,15 @@
284 284
   (5am:is (equal (funcall (data-lens:transform 1)
285 285
                           (data-lens:juxt '1- 'identity '1+))
286 286
                  '(0 1 2))))
287
+
288
+(5am:def-test calling (:suite :data-lens.lens :depends-on (and functionalize))
289
+  (5am:is (equal (funcall (data-lens:calling #'- 1) 3)
290
+                 2))
291
+  (5am:is (equal (funcall (data-lens:calling #'- 2 1) 3)
292
+                 0)))
293
+
294
+(5am:def-test calling* (:suite :data-lens.lens :depends-on (and functionalize))
295
+  (5am:is (equal (funcall (data-lens:calling* #'- 3) 1)
296
+                 2))
297
+  (5am:is (equal (funcall (data-lens:calling* #'- 3 2) 1)
298
+                 0)))