[Docs] Note that partition(by:) is unstable (#39384)

This commit is contained in:
Nate Cook
2021-09-29 13:54:31 -05:00
committed by GitHub
parent 9841d1c5df
commit 2daa005c5c
2 changed files with 21 additions and 3 deletions

View File

@@ -221,7 +221,9 @@ extension MutableCollection {
/// After partitioning a collection, there is a pivot index `p` where
/// no element before `p` satisfies the `belongsInSecondPartition`
/// predicate and every element at or after `p` satisfies
/// `belongsInSecondPartition`.
/// `belongsInSecondPartition`. This operation isn't guaranteed to be
/// stable, so the relative ordering of elements within the partitions might
/// change.
///
/// In the following example, an array of numbers is partitioned by a
/// predicate that matches elements greater than 30.
@@ -241,6 +243,10 @@ extension MutableCollection {
/// let second = numbers[p...]
/// // second == [60, 40]
///
/// Note that the order of elements in both partitions changed.
/// That is, `40` appears before `60` in the original collection,
/// but, after calling `partition(by:)`, `60` appears before `40`.
///
/// - Parameter belongsInSecondPartition: A predicate used to partition
/// the collection. All elements satisfying this predicate are ordered
/// after all elements not satisfying it.
@@ -285,7 +291,9 @@ extension MutableCollection where Self: BidirectionalCollection {
/// After partitioning a collection, there is a pivot index `p` where
/// no element before `p` satisfies the `belongsInSecondPartition`
/// predicate and every element at or after `p` satisfies
/// `belongsInSecondPartition`.
/// `belongsInSecondPartition`. This operation isn't guaranteed to be
/// stable, so the relative ordering of elements within the partitions might
/// change.
///
/// In the following example, an array of numbers is partitioned by a
/// predicate that matches elements greater than 30.
@@ -305,6 +313,10 @@ extension MutableCollection where Self: BidirectionalCollection {
/// let second = numbers[p...]
/// // second == [60, 40]
///
/// Note that the order of elements in both partitions changed.
/// That is, `40` appears before `60` in the original collection,
/// but, after calling `partition(by:)`, `60` appears before `40`.
///
/// - Parameter belongsInSecondPartition: A predicate used to partition
/// the collection. All elements satisfying this predicate are ordered
/// after all elements not satisfying it.