aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2024-09-30 01:30:55 +0100
committerArun Isaac2024-10-01 01:12:51 +0100
commit033aa1d3e5ed265bc5171eadd560d6c886afc69d (patch)
tree4b853f2150681ee53bd78d05ea93efc0d5e32c52
parent5dbe02ae9028137221a9466af906e804293dff10 (diff)
downloadravanan-033aa1d3e5ed265bc5171eadd560d6c886afc69d.tar.gz
ravanan-033aa1d3e5ed265bc5171eadd560d6c886afc69d.tar.lz
ravanan-033aa1d3e5ed265bc5171eadd560d6c886afc69d.zip
vectors: Add vector-mapn.
* ravanan/work/vectors.scm: Import (srfi srfi-26). (vector-mapn): New public function.
-rw-r--r--ravanan/work/vectors.scm14
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)))