core: Don't copy elements in filter_map
This commit is contained in:
parent
35e9970e29
commit
3ee4a15e5e
1 changed files with 2 additions and 2 deletions
|
@ -430,11 +430,11 @@ Apply a function to each element of a vector and return the results
|
||||||
If function `f` returns `none` then that element is excluded from
|
If function `f` returns `none` then that element is excluded from
|
||||||
the resulting vector.
|
the resulting vector.
|
||||||
"]
|
"]
|
||||||
fn filter_map<T: copy, U: copy>(v: [const T], f: fn(T) -> option<U>)
|
fn filter_map<T: copy, U: copy>(v: [T], f: fn(T) -> option<U>)
|
||||||
-> [U] {
|
-> [U] {
|
||||||
let mut result = [];
|
let mut result = [];
|
||||||
for elem: T in v {
|
for elem: T in v {
|
||||||
alt f(copy elem) {
|
alt f(elem) {
|
||||||
none {/* no-op */ }
|
none {/* no-op */ }
|
||||||
some(result_elem) { result += [result_elem]; }
|
some(result_elem) { result += [result_elem]; }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue