-
Notifications
You must be signed in to change notification settings - Fork 560
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(corelib): iter::adapters::Filter (#7152)
- Loading branch information
Showing
4 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/// An iterator that filters the elements of `iter` with `predicate`. | ||
/// | ||
/// This `struct` is created by the [`filter`] method on [`Iterator`]. See its | ||
/// documentation for more. | ||
/// | ||
/// [`filter`]: Iterator::filter | ||
#[must_use] | ||
#[derive(Drop, Clone)] | ||
pub struct Filter<I, P> { | ||
pub iter: I, | ||
pub predicate: P, | ||
} | ||
|
||
pub fn filter_iterator<I, P>(iter: I, predicate: P) -> Filter<I, P> { | ||
Filter { iter, predicate } | ||
} | ||
|
||
impl FilterIterator< | ||
I, | ||
P, | ||
impl TIter: Iterator<I>, | ||
+core::ops::Fn<P, (@TIter::Item,)>[Output: bool], | ||
+Destruct<I>, | ||
+Destruct<P>, | ||
+Destruct<TIter::Item>, | ||
> of Iterator<Filter<I, P>> { | ||
type Item = TIter::Item; | ||
fn next(ref self: Filter<I, P>) -> Option<Self::Item> { | ||
self.iter.find(@self.predicate) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters