stdlib: Add vec::concat to concatenate a vector of vectors

Compare to str::concat
This commit is contained in:
Brian Anderson 2011-10-29 17:23:58 -07:00
parent da064ef884
commit 2e0593d999
2 changed files with 18 additions and 0 deletions

View File

@ -446,6 +446,19 @@ fn filter<T>(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<T>(v: [mutable? [mutable? T]]) -> [T] {
// FIXME: So much copying
let new: [T] = [];
for inner: [T] in v { new += inner; }
ret new;
}
/*
Function: foldl

View File

@ -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;