summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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