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

Add core::iter::once_with() #57579

Merged
merged 6 commits into from Jan 15, 2019
Merged

Add core::iter::once_with() #57579

merged 6 commits into from Jan 15, 2019

Conversation

ghost
Copy link

@ghost ghost commented Jan 13, 2019

Functions iter::once() and iter::repeat() construct iterators from values. The latter has the lazy variant iter::repeat_with(), but the former doesn't. This PR therefore adds iter::once_with().

Another way to think of iter::once_with() is that it's a function that converts FnOnce() -> T into Iterator<Item = T>.

If this seems like a reasonable addition, I'll open a tracking issue and update the #[feature(...)] attributes.

@rust-highfive

This comment has been minimized.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 13, 2019
@rust-highfive

This comment has been minimized.

@frewsxcv frewsxcv added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Jan 13, 2019
@frewsxcv
Copy link
Member

cc @rust-lang/libs

@Centril
Copy link
Contributor

Centril commented Jan 13, 2019

r? @SimonSapin

I once promised @eddyb to make a PR for this but the playground ate my work... :(
Thank you for writing this up!

@rust-highfive

This comment has been minimized.

@rust-highfive

This comment has been minimized.

@rust-highfive

This comment has been minimized.

@SimonSapin
Copy link
Contributor

r=me, but the doc-comment still needs #![feature(iter_once_with)]

/// over each file of the `.foo` directory, but also a configuration file,
/// `.foorc`:
///
/// ```no_run
Copy link
Contributor

Choose a reason for hiding this comment

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

I’d guess here too? IIRC no_run doc-tests are still compiled.

@SimonSapin
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jan 14, 2019

📌 Commit 3a1f013 has been approved by SimonSapin

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 14, 2019
Centril added a commit to Centril/rust that referenced this pull request Jan 15, 2019
Add core::iter::once_with()

Functions `iter::once()` and `iter::repeat()` construct iterators from values. The latter has the lazy variant `iter::repeat_with()`, but the former doesn't. This PR therefore adds `iter::once_with()`.

Another way to think of `iter::once_with()` is that it's a function that converts `FnOnce() -> T` into `Iterator<Item = T>`.

If this seems like a reasonable addition, I'll open a tracking issue and update the `#[feature(...)]` attributes.
Centril added a commit to Centril/rust that referenced this pull request Jan 15, 2019
Add core::iter::once_with()

Functions `iter::once()` and `iter::repeat()` construct iterators from values. The latter has the lazy variant `iter::repeat_with()`, but the former doesn't. This PR therefore adds `iter::once_with()`.

Another way to think of `iter::once_with()` is that it's a function that converts `FnOnce() -> T` into `Iterator<Item = T>`.

If this seems like a reasonable addition, I'll open a tracking issue and update the `#[feature(...)]` attributes.
bors added a commit that referenced this pull request Jan 15, 2019
Rollup of 7 pull requests

Successful merges:

 - #57253 (Make privacy checking, intrinsic checking and liveness checking incremental)
 - #57352 (forbid manually impl'ing one of an object type's marker traits)
 - #57537 (Small perf improvement for fmt)
 - #57579 (Add core::iter::once_with())
 - #57587 (Add 'rustc-env:RUST_BACKTRACE=0' to const-pat-ice test)
 - #57608 (Simplify 'product' factorial example)
 - #57614 ([rustdoc] Fix crates filtering box not being filled)

Failed merges:

r? @ghost
Centril added a commit to Centril/rust that referenced this pull request Jan 15, 2019
Add core::iter::once_with()

Functions `iter::once()` and `iter::repeat()` construct iterators from values. The latter has the lazy variant `iter::repeat_with()`, but the former doesn't. This PR therefore adds `iter::once_with()`.

Another way to think of `iter::once_with()` is that it's a function that converts `FnOnce() -> T` into `Iterator<Item = T>`.

If this seems like a reasonable addition, I'll open a tracking issue and update the `#[feature(...)]` attributes.
bors added a commit that referenced this pull request Jan 15, 2019
Rollup of 8 pull requests

Successful merges:

 - #56044 (Drop partially bound function parameters in the expected order)
 - #57352 (forbid manually impl'ing one of an object type's marker traits)
 - #57456 (RawVec doesn't always abort on allocation errors)
 - #57467 (Implement `check_attribute` to forbid `#[allow_internal_unsafe]`)
 - #57579 (Add core::iter::once_with())
 - #57587 (Add 'rustc-env:RUST_BACKTRACE=0' to const-pat-ice test)
 - #57608 (Simplify 'product' factorial example)
 - #57614 ([rustdoc] Fix crates filtering box not being filled)

Failed merges:

r? @ghost
@bors bors merged commit 3a1f013 into rust-lang:master Jan 15, 2019
@ghost ghost deleted the once-with branch January 15, 2019 16:51
@@ -377,6 +377,119 @@ pub fn once<T>(value: T) -> Once<T> {
Once { inner: Some(value).into_iter() }
}

/// An iterator that repeats elements of type `A` endlessly by
/// applying the provided closure `F: FnMut() -> A`.
///
Copy link

Choose a reason for hiding this comment

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

It seems like his comment was copy pasted from RepeatWith.
It talks about endless repeating and FnMut().

Copy link
Contributor

Choose a reason for hiding this comment

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

@kumbayo could you file a PR to fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants