From e1505232e21b6cb52921fc9bb8ee29f2772ab4a8 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Tue, 1 Jun 2021 13:59:35 +0530 Subject: Add filter-mapi. * ccwl/utils.scm (filter-mapi): New public function. --- ccwl/utils.scm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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 -- cgit v1.2.3