diff options
-rw-r--r-- | ravanan/work/vectors.scm | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/ravanan/work/vectors.scm b/ravanan/work/vectors.scm index 993fb49..b481b62 100644 --- a/ravanan/work/vectors.scm +++ b/ravanan/work/vectors.scm @@ -19,6 +19,7 @@ (define-module (ravanan work vectors) #:use-module ((rnrs base) #:select (vector-for-each vector-map)) #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) #:use-module ((srfi srfi-43) #:select (vector-append (vector-map . vector-map-indexed) vector-any @@ -27,6 +28,7 @@ #:export (vector-map->list vector-append-map vector-append-map->list + vector-mapn map->vector vector-fold vector-filter @@ -87,6 +89,18 @@ together." first-vector other-vectors)) +(define (vector-mapn proc vec) + "Map @var{proc} over elements of @var{vec} and return a vector of the results. +@var{proc} may return multiple values, and this function returns the same number +of vectors." + (apply values + (map list->vector + (apply zip + (vector-map->list (lambda (element) + (call-with-values (cut proc element) + list)) + vec))))) + (define (map->vector proc first-list . other-lists) "Map @var{proc} over lists and return a vector of the results." (list->vector (apply map proc first-list other-lists))) |