git.fiddlerwoaroof.com
Browse code

feat(on): make on more conformant with the Haskell function

Edward Langley authored on 30/03/2022 03:37:02
Showing 1 changed files
... ...
@@ -269,10 +269,16 @@
269 269
          (apply ,fsym ,@args ,seq)))))
270 270
 
271 271
 (defun-ct on (fun key)
272
+  "Transform arguments with KEY and then apply FUN
273
+
274
+> (eql (funcall (on 'equal 'car)
275
+>          '(\"a\" 1 2)
276
+>          '(\"a\" 2 e))
277
+>      t)"
272 278
   (let ((fun (functionalize fun))
273 279
         (key (functionalize key)))
274
-    (lambda (it)
275
-      (funcall fun (funcall key it)))))
280
+    (lambda (&rest its)
281
+      (funcall fun (mapcar key its)))))
276 282
 
277 283
 (defun filler (length1 length2 fill-value)
278 284
   (if (< length1 length2)