Skip to content

impl IntoIterator for GenericArray #13

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 1 commit into from
Jun 4, 2016
Merged

Conversation

cuviper
Copy link
Contributor

@cuviper cuviper commented May 25, 2016

This allows an array to move its values out through iteration. I find this especially handy for flat_map, to expand one item into several without having to allocate a Vec, like the new test:

fn test_iter_flat_map() {
    assert!((0..5).flat_map(|i| arr![i32; 2 * i, 2 * i + 1]).eq(0..10));
}

This is a spiritual successor to rust-lang/rust#32871, which was declined at least until it could use integer generics. GenericArray fills that gap, though, and could use IntoIterator today.

This allows an array to move its values out through iteration. I find
this especially handy for flat_map, to expand one item into several
without having to allocate a Vec, like the new test:

```rust
fn test_iter_flat_map() {
    assert!((0..5).flat_map(|i| arr![i32; 2 * i, 2 * i + 1]).eq(0..10));
}
```

This is a spiritual successor to rust-lang/rust#32871, which was
declined at least until it could use integer generics.  GenericArray
fills that gap, though, and could use IntoIterator today.
@fizyk20
Copy link
Owner

fizyk20 commented Jun 4, 2016

That's useful, thanks!

@fizyk20 fizyk20 merged commit c9d53d6 into fizyk20:master Jun 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants