stdlib: Add vec::concat to concatenate a vector of vectors
Compare to str::concat
This commit is contained in:
parent
da064ef884
commit
2e0593d999
@ -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
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user