mirror of
https://github.com/fiddlerwoaroof/data-lens.git
synced 2025-11-08 10:16:32 +00:00
Add functions for transforming arbitrary elements and applying functions
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1,3 @@
|
||||
*.fasl
|
||||
*.*x*fsl
|
||||
*~
|
||||
|
||||
15
lens.lisp
15
lens.lisp
@ -20,7 +20,9 @@
|
||||
#:of-max-length
|
||||
#:transform-head
|
||||
#:maximizing
|
||||
#:zipping))
|
||||
#:zipping
|
||||
#:applying
|
||||
#:transform-elt))
|
||||
(in-package :data-lens)
|
||||
|
||||
(declaim
|
||||
@ -163,6 +165,12 @@
|
||||
(list* (car it)
|
||||
(funcall fun (cdr it)))))
|
||||
|
||||
(defun-ct transform-elt (elt fun)
|
||||
(lambda (it)
|
||||
(append (subseq it 0 elt)
|
||||
(funcall fun (nth elt it))
|
||||
(subseq it (1+ elt)))))
|
||||
|
||||
(defun-ct key-transform (fun key-get key-set)
|
||||
(lambda (it)
|
||||
(let ((key-val (funcall key-get it)))
|
||||
@ -214,6 +222,11 @@
|
||||
(lambda (seq)
|
||||
(map result-type fun seq)))
|
||||
|
||||
(defmacro applying (fun &rest args)
|
||||
(alexandria:with-gensyms (seq)
|
||||
`(lambda (,seq)
|
||||
(apply ,fun ,@args ,seq))))
|
||||
|
||||
(defun-ct on (fun key)
|
||||
(lambda (it)
|
||||
(funcall fun (funcall key it))))
|
||||
|
||||
Reference in New Issue
Block a user