Tracking issue for RFC 2351, "Add is_sorted
to the standard library" (original) (raw)
Navigation Menu
- GitHub Copilot Write better code with AI
- GitHub Models New Manage and compare prompts
- GitHub Advanced Security Find and fix vulnerabilities
- Actions Automate any workflow
- Codespaces Instant dev environments
- Issues Plan and track work
- Code Review Manage code changes
- Discussions Collaborate outside of code
- Code Search Find more, search less
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
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] { 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 to Iterator 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 only PartialOrd?
- Answered by Make is_sorted[_by_key] require Ord instead of PartialOrd and remove Iterator::is_sorted_by_key #81382 (comment) (no,
PartialOrd
is the right bound)
- Answered by Make is_sorted[_by_key] require Ord instead of PartialOrd and remove Iterator::is_sorted_by_key #81382 (comment) (no,
- 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>
?