Skip to content
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

we need a convenient collect(), collect_into() should support other collection types #123

Closed
nikomatsakis opened this issue Oct 25, 2016 · 4 comments
Labels
Milestone

Comments

@nikomatsakis
Copy link
Member

In general, it'd be nice if collect_into() were more flexible and convenient. We may need multiple APIs in the end. Some things I would like:

  • a convenient collect() that allocates a new collection, as with sequential iterators;
  • maybe rename collect_into() into extend() and have it work like extend()?
    • this is possible for vectors, at least
  • support for some more collection types:
    • for exact length iterators, we could support slices (not vectors)
      • but we'd have to assert that their length is correct
    • concurrent collections could be easily supported
    • also persistent collections like https://github.com/michaelwoerister/hamt-rs
    • maybe worth supporting something like RwLock<&mut HashMap>
      • could be practical in some scenarios...
      • or maybe collecting up pairs in a vec and then (transparently) storing them into the hashmap after, as a seq step?
  • support for more parallel iterator types:
    • vecs can support bounded iterators, but they need a "compact" step
      • have to be careful about panics, though we can leak if needed

Well, ok, that's not very organized. But I feel like we can put a bit more effort into making this ergonomic and "bridging" between various things. I'm torn. =)

I suspect we'll wind up with more than just collect_into, in any case, though specialization might help here too.

@nikomatsakis nikomatsakis added this to the 1.0 milestone Oct 25, 2016
@nikomatsakis
Copy link
Member Author

Marking as 1.0 -- some parts of this, e.g. collect and at least a trait-ified collect_into, we should have. The rest maybe not.

@jwilm
Copy link

jwilm commented Nov 16, 2016

I'm interested in a collect_into() that works on a bounded iterator. Hoping to be able to achieve something like:

items.par_iter()
     .filter_map(func)
     .collect_into(&mut existing_vec);

What is the compaction step you're talking about? It seems like it should be possible to tightly pack the vec being collected into using an atomic counter for the next index to write into.

@nikomatsakis
Copy link
Member Author

@jwilm I'm going to open a separate issue for this. I'll spell out how I think it should work. An atomic counter is not needed.

@nikomatsakis
Copy link
Member Author

(Closing because we now have a collect() API)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants