-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Add core::iter::once_with() #57579
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
cc @rust-lang/libs |
r? @SimonSapin I once promised @eddyb to make a PR for this but the playground ate my work... :( |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
r=me, but the doc-comment still needs |
/// over each file of the `.foo` directory, but also a configuration file, | ||
/// `.foorc`: | ||
/// | ||
/// ```no_run |
There was a problem hiding this comment.
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.
@bors r+ |
📌 Commit 3a1f013 has been approved by |
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.
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.
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
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.
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
@@ -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`. | |||
/// |
There was a problem hiding this comment.
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()
.
There was a problem hiding this comment.
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?
Functions
iter::once()
anditer::repeat()
construct iterators from values. The latter has the lazy variantiter::repeat_with()
, but the former doesn't. This PR therefore addsiter::once_with()
.Another way to think of
iter::once_with()
is that it's a function that convertsFnOnce() -> T
intoIterator<Item = T>
.If this seems like a reasonable addition, I'll open a tracking issue and update the
#[feature(...)]
attributes.