Skip to content

Commit 7c60ebd

Browse files
committed
---
yaml --- r: 52180 b: refs/heads/dist-snap c: c766924 h: refs/heads/master v: v3
1 parent 502d8d1 commit 7c60ebd

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
99
refs/heads/incoming: 44d4d6de762f3f9aae1fedcf454c66b79b3ad58d
10-
refs/heads/dist-snap: 2891a49f0d9b3c6cdd4fa8b0bd1f2a5d06cdac58
10+
refs/heads/dist-snap: c766924f44038d47108346bf237f510a3c869bf2
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1313
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/libcore/vec.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,21 @@ pub pure fn filter_map<T, U: Copy>(v: &[T], f: fn(t: &T) -> Option<U>)
846846
result
847847
}
848848

849+
/**
850+
* Construct a new vector from the elements of a vector for which some
851+
* predicate holds.
852+
*
853+
* Apply function `f` to each element of `v` and return a vector containing
854+
* only those elements for which `f` returned true.
855+
*/
856+
pub fn filter<T>(v: ~[T], f: fn(t: &T) -> bool) -> ~[T] {
857+
let mut result = ~[];
858+
do v.consume |_, elem| {
859+
if f(&elem) { result.push(elem); }
860+
}
861+
result
862+
}
863+
849864
/**
850865
* Construct a new vector from the elements of a vector for which some
851866
* predicate holds.
@@ -1805,6 +1820,7 @@ pub trait OwnedVector<T> {
18051820
fn truncate(&mut self, newlen: uint);
18061821
fn retain(&mut self, f: pure fn(t: &T) -> bool);
18071822
fn consume(self, f: fn(uint, v: T));
1823+
fn filter(self, f: fn(t: &T) -> bool) -> ~[T];
18081824
fn partition(self, f: pure fn(&T) -> bool) -> (~[T], ~[T]);
18091825
}
18101826

@@ -1864,6 +1880,11 @@ impl<T> ~[T]: OwnedVector<T> {
18641880
consume(self, f)
18651881
}
18661882

1883+
#[inline]
1884+
fn filter(self, f: fn(&T) -> bool) -> ~[T] {
1885+
filter(self, f)
1886+
}
1887+
18671888
/**
18681889
* Partitions the vector into those that satisfies the predicate, and
18691890
* those that do not.

0 commit comments

Comments
 (0)