diff --git a/src/lib/vec.rs b/src/lib/vec.rs index 548afaa73bc9..f459a75270a4 100644 --- a/src/lib/vec.rs +++ b/src/lib/vec.rs @@ -446,6 +446,19 @@ fn filter(f: block(T) -> bool, v: [mutable? T]) -> [T] { ret result; } +/* +Function: concat + +Concatenate a vector of vectors. Flattens a vector of vectors of T into +a single vector of T. +*/ +fn concat(v: [mutable? [mutable? T]]) -> [T] { + // FIXME: So much copying + let new: [T] = []; + for inner: [T] in v { new += inner; } + ret new; +} + /* Function: foldl diff --git a/src/test/stdtest/vec.rs b/src/test/stdtest/vec.rs index 5f644c450b6d..1bbb003e1c4e 100644 --- a/src/test/stdtest/vec.rs +++ b/src/test/stdtest/vec.rs @@ -469,6 +469,11 @@ fn init_empty() { #[ignore] fn init_empty() { } +#[test] +fn concat() { + assert vec::concat([[1], [2,3]]) == [1, 2, 3]; +} + // Local Variables: // mode: rust; // fill-column: 78;