Suggestion: rush() — eagerly takes n first elements of an iterable an leaves the rest
See original GitHub issueExample
const [rushed, rest] = rush(4, range())
Expect:
rushed
should be an array of 4 numbers:[0, 1, 2, 3]
rest
should be an iterator starting from 4
Issue Analytics
- State:
- Created 5 years ago
- Comments:24 (9 by maintainers)
Top Results From Across the Web
How to skip the first n item(s) of an iterator in Rust?
The question posted is very specific to iterators and how to skip n elements while using an iterator. This answer collects the iterator...
Read more >first() in iterator · Issue #2833 · rust-lang/rfcs - GitHub
std::iter::Iterator has a method to get the last element, last(). But why isn't there a first() to get the first element?
Read more >Why can't for-of be applied to iterators? - ESDiscuss.org
Another use case for iterator support: retrieve the first element from an iterator, then iterate over the remaining elements via for-of.
Read more >Rust Iterator Cheat Sheet
Most iterator methods take their first input by-value; those that don't are marked with a &mut &mut out the front of their first...
Read more >Iterator in std::iter - Rust
Specifically, size_hint() returns a tuple where the first element is the lower ... This method will eagerly skip n elements by calling next...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So I guess I should reopen https://github.com/sithmel/iter-tools/issues/134 then.
Yeah, indeed it would. It could use a simple array cache though since it would know right up front how many elements it was going to need to cache, and it could avoid making the array cache at all if no items were consumed from the latter half of the split before the iterable for the first half of the split was exhausted, which would be the case in the sample code above.