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

Stream::cycle implementation #34

Closed

Conversation

vertexclique
Copy link
Member

@vertexclique vertexclique commented Aug 15, 2019

  • Adds stream::cycle implementation
  • Contains an example for stream cycle.

Copy link
Contributor

@yoshuawuyts yoshuawuyts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few notes!


Ok(())
})
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example is cool, but I think it's probably fine to just have the doc test for now. In #131 and #129 there are quite a few more methods, and I think it'd be wise to try and keep our line count down where possible.

src/stream/cycle.rs Show resolved Hide resolved
/// use async_std::stream;
///
/// let mut s = stream::cycle(vec![1, 2, 3]);
///
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In std the API is:

let a = [1, 2, 3];

let mut it = a.iter().cycle();

assert_eq!(it.next(), Some(&1));
assert_eq!(it.next(), Some(&2));
assert_eq!(it.next(), Some(&3));
assert_eq!(it.next(), Some(&1));
assert_eq!(it.next(), Some(&2));
assert_eq!(it.next(), Some(&3));
assert_eq!(it.next(), Some(&1));

I'd expect this API to be (with #125 landed):

let a = [1, 2, 3];

let mut it = a.into_stream().cycle();

assert_eq!(it.next().await, Some(&1));
assert_eq!(it.next().await, Some(&2));
assert_eq!(it.next().await, Some(&3));
assert_eq!(it.next().await, Some(&1));
assert_eq!(it.next().await, Some(&2));
assert_eq!(it.next().await, Some(&3));
assert_eq!(it.next().await, Some(&1));

Similar, but subtly different in that it's more generic, which should make it more widely applicable!

@yoshuawuyts
Copy link
Contributor

#125 has landed now which means this can be modeled after std's API. @vertexclique do you have any interest in continuing with this patch in that direction?

@yoshuawuyts yoshuawuyts added the enhancement New feature or request label Sep 18, 2019
@yoshuawuyts
Copy link
Contributor

It's been a while, and I'm going to assume this PR will not be continued. Thanks for the work! Going to go ahead and close this.

moh-eulith pushed a commit to moh-eulith/async-std that referenced this pull request Mar 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants