-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-iteratorsArea: IteratorsArea: IteratorsA-sliceArea: `[T]`Area: `[T]`B-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.Blocker: Approved by a merged RFC but not yet implemented.B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCLibs-SmallLibs issues that are considered "small" or self-containedLibs issues that are considered "small" or self-containedLibs-TrackedLibs issues that are tracked on the team's project board.Libs issues that are tracked on the team's project board.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Description
Feature gate: #![feature(is_sorted)]
This is a tracking issue for is_sorted{_by,_by_key}
functions on [T]
and Iterator
(rust-lang/rfcs#2351).
Public API
impl<T> [T] {
pub fn is_sorted(&self) -> bool
where
T: PartialOrd;
pub fn is_sorted_by<'a, F>(&'a self, mut compare: F) -> bool
where
F: FnMut(&'a T, &'a T) -> bool;
pub fn is_sorted_by_key<'a, F, K>(&'a self, f: F) -> bool
where
F: FnMut(&'a T) -> K,
K: PartialOrd;
}
// core::iter
pub trait Iterator {
// all the other methods omitted
fn is_sorted(self) -> bool
where
Self: Sized,
Self::Item: PartialOrd;
fn is_sorted_by<F>(mut self, compare: F) -> bool
where
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> bool;
fn is_sorted_by_key<F, K>(self, f: F) -> bool
where
Self: Sized,
F: FnMut(Self::Item) -> K,
K: PartialOrd;
}
Steps / History
- Implementation: Add
is_sorted
toIterator
and[T]
#55045 - Only call the closure parameter of Iterator::is_sorted_by_key once per item #62473
- remove HRTB from
[T]::is_sorted_by{,_key}
#102977 - Add more comprehensive tests for is_sorted and friends #112699
- Final comment period (FCP)1
- Stabilization PR
Unresolved Questions
- Require
Ord
instead of onlyPartialOrd
?- Answered by Make
is_sorted[_by_key]
requireOrd
instead ofPartialOrd
and removeIterator::is_sorted_by_key
#81382 (comment) (no,PartialOrd
is the right bound)
- Answered by Make
- Should
Iterator::is_sorted_by_key
be added as well?- It was added in the original implementation PR
- Add
std::cmp::is_sorted
instead? - Should
is_sorted_by
take a closure returningbool
instead ofOption<Ordering>
?
Footnotes
gliderkite, stanislav-tkach, ryoqun, amrhassan, peterkos and 43 moreschneiderfelipeschneiderfelipehombit, amrhassan, spacejam, Kobzol, brainstorm and 3 moreschneiderfelipe
Metadata
Metadata
Assignees
Labels
A-iteratorsArea: IteratorsArea: IteratorsA-sliceArea: `[T]`Area: `[T]`B-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.Blocker: Approved by a merged RFC but not yet implemented.B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCLibs-SmallLibs issues that are considered "small" or self-containedLibs issues that are considered "small" or self-containedLibs-TrackedLibs issues that are tracked on the team's project board.Libs issues that are tracked on the team's project board.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.