Skip to content

Customize <FlatMap as Iterator>::fold #44577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 17, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add a specific test for FlatMap::fold
  • Loading branch information
cuviper committed Sep 15, 2017
commit 351f56a6034486c38c3b36bfbbd15a81a39ba9aa
16 changes: 16 additions & 0 deletions src/libcore/tests/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,22 @@ fn test_iterator_flat_map() {
assert_eq!(i, ys.len());
}

/// Test `FlatMap::fold` with items already picked off the front and back,
/// to make sure all parts of the `FlatMap` are folded correctly.
#[test]
fn test_iterator_flat_map_fold() {
let xs = [0, 3, 6];
let ys = [1, 2, 3, 4, 5, 6, 7];
let mut it = xs.iter().flat_map(|&x| x..x+3);
it.next();
it.next_back();
let i = it.fold(0, |i, x| {
assert_eq!(x, ys[i]);
i + 1
});
assert_eq!(i, ys.len());
}

#[test]
fn test_inspect() {
let xs = [1, 2, 3, 4];
Expand Down