diff options
Diffstat (limited to 'src/lib/_vec.rs')
| -rw-r--r-- | src/lib/_vec.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/lib/_vec.rs b/src/lib/_vec.rs index 6fa0ed42..2ffe8bad 100644 --- a/src/lib/_vec.rs +++ b/src/lib/_vec.rs @@ -1,6 +1,8 @@ import vbuf = rustrt.vbuf; import std.option; +type operator2[T,U,V] = fn(&T, &U) -> V; + native "rust" mod rustrt { type vbuf; @@ -142,6 +144,22 @@ fn map[T, U](&option.operator[T,U] f, &vec[T] v) -> vec[U] { ret u; } +fn map2[T,U,V](&operator2[T,U,V] f, &vec[T] v0, &vec[U] v1) -> vec[V] { + auto v0_len = len[T](v0); + if (v0_len != len[U](v1)) { + fail; + } + + let vec[V] u = alloc[V](v0_len); + auto i = 0u; + while (i < v0_len) { + u += f(v0.(i), v1.(i)); + i += 1u; + } + + ret u; +} + // Local Variables: // mode: rust; // fill-column: 78; |