question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Suggestion: rush() — eagerly takes n first elements of an iterable an leaves the rest

See original GitHub issue

Example

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:closed
  • Created 5 years ago
  • Comments:24 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
KSXGitHubcommented, Jan 19, 2019

So I guess I should reopen https://github.com/sithmel/iter-tools/issues/134 then.

1reaction
conartist6commented, Jan 19, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found