summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2021-06-01 13:59:35 +0530
committerArun Isaac2021-06-01 13:59:35 +0530
commite1505232e21b6cb52921fc9bb8ee29f2772ab4a8 (patch)
treefa026e332e21f27b47d912ffbedf11128cf143d2
parent49020e72a73adb730143be2dc3c3232fab9fff1e (diff)
downloadccwl-e1505232e21b6cb52921fc9bb8ee29f2772ab4a8.tar.gz
ccwl-e1505232e21b6cb52921fc9bb8ee29f2772ab4a8.tar.lz
ccwl-e1505232e21b6cb52921fc9bb8ee29f2772ab4a8.zip
Add filter-mapi.
* ccwl/utils.scm (filter-mapi): New public function.
-rw-r--r--ccwl/utils.scm12
1 files changed, 11 insertions, 1 deletions
diff --git a/ccwl/utils.scm b/ccwl/utils.scm
index d0db51c..de25fcc 100644
--- a/ccwl/utils.scm
+++ b/ccwl/utils.scm
@@ -33,7 +33,8 @@
syntax-lambda**
mapn
append-mapn
- foldn))
+ foldn
+ filter-mapi))
(define (pairify lst)
"Return a list of pairs of successive elements of LST."
@@ -145,6 +146,15 @@ macros that accept keyword arguments."
((_ args :::)
(unsyntax-keywords #'(args :::))))))))
+(define (filter-mapi proc lst)
+ "Indexed filter-map. Like filter-map, but PROC calls are (proc item
+index) where ITEM is an element of list and INDEX is the index of that
+element."
+ (filter-map (lambda (item index)
+ (proc item index))
+ lst
+ (iota (length lst))))
+
(define (mapn proc lst)
"Map the procedure PROC over list LST and return a list containing
the results. PROC can return multiple values, in which case, an equal