Closed
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
Metadata
Metadata
Assignees
Labels
Area: IteratorsArea: `[T]`Blocker: Approved by a merged RFC but not yet implemented.Blocker: Implemented in the nightly compiler and unstable.Category: An issue tracking the progress of sth. like the implementation of an RFCLibs issues that are considered "small" or self-containedLibs issues that are tracked on the team's project board.Relevant to the library API team, which will review and decide on the PR/issue.This issue / PR is in PFCP or FCP with a disposition to merge it.The final comment period is finished for this PR / Issue.