Skip to content

Commit 2daa005

Browse files
authored
[Docs] Note that partition(by:) is unstable (#39384)
1 parent 9841d1c commit 2daa005

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

stdlib/public/core/CollectionAlgorithms.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,9 @@ extension MutableCollection {
221221
/// After partitioning a collection, there is a pivot index `p` where
222222
/// no element before `p` satisfies the `belongsInSecondPartition`
223223
/// predicate and every element at or after `p` satisfies
224-
/// `belongsInSecondPartition`.
224+
/// `belongsInSecondPartition`. This operation isn't guaranteed to be
225+
/// stable, so the relative ordering of elements within the partitions might
226+
/// change.
225227
///
226228
/// In the following example, an array of numbers is partitioned by a
227229
/// predicate that matches elements greater than 30.
@@ -241,6 +243,10 @@ extension MutableCollection {
241243
/// let second = numbers[p...]
242244
/// // second == [60, 40]
243245
///
246+
/// Note that the order of elements in both partitions changed.
247+
/// That is, `40` appears before `60` in the original collection,
248+
/// but, after calling `partition(by:)`, `60` appears before `40`.
249+
///
244250
/// - Parameter belongsInSecondPartition: A predicate used to partition
245251
/// the collection. All elements satisfying this predicate are ordered
246252
/// after all elements not satisfying it.
@@ -285,7 +291,9 @@ extension MutableCollection where Self: BidirectionalCollection {
285291
/// After partitioning a collection, there is a pivot index `p` where
286292
/// no element before `p` satisfies the `belongsInSecondPartition`
287293
/// predicate and every element at or after `p` satisfies
288-
/// `belongsInSecondPartition`.
294+
/// `belongsInSecondPartition`. This operation isn't guaranteed to be
295+
/// stable, so the relative ordering of elements within the partitions might
296+
/// change.
289297
///
290298
/// In the following example, an array of numbers is partitioned by a
291299
/// predicate that matches elements greater than 30.
@@ -305,6 +313,10 @@ extension MutableCollection where Self: BidirectionalCollection {
305313
/// let second = numbers[p...]
306314
/// // second == [60, 40]
307315
///
316+
/// Note that the order of elements in both partitions changed.
317+
/// That is, `40` appears before `60` in the original collection,
318+
/// but, after calling `partition(by:)`, `60` appears before `40`.
319+
///
308320
/// - Parameter belongsInSecondPartition: A predicate used to partition
309321
/// the collection. All elements satisfying this predicate are ordered
310322
/// after all elements not satisfying it.

stdlib/public/core/MutableCollection.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ where SubSequence: MutableCollection
121121
/// After partitioning a collection, there is a pivot index `p` where
122122
/// no element before `p` satisfies the `belongsInSecondPartition`
123123
/// predicate and every element at or after `p` satisfies
124-
/// `belongsInSecondPartition`.
124+
/// `belongsInSecondPartition`. This operation isn't guaranteed to be
125+
/// stable, so the relative ordering of elements within the partitions might
126+
/// change.
125127
///
126128
/// In the following example, an array of numbers is partitioned by a
127129
/// predicate that matches elements greater than 30.
@@ -141,6 +143,10 @@ where SubSequence: MutableCollection
141143
/// let second = numbers[p...]
142144
/// // second == [60, 40]
143145
///
146+
/// Note that the order of elements in both partitions changed.
147+
/// That is, `40` appears before `60` in the original collection,
148+
/// but, after calling `partition(by:)`, `60` appears before `40`.
149+
///
144150
/// - Parameter belongsInSecondPartition: A predicate used to partition
145151
/// the collection. All elements satisfying this predicate are ordered
146152
/// after all elements not satisfying it.

0 commit comments

Comments
 (0)