From 88fa53b5ea35b8da7e3f578254583e249cd58394 Mon Sep 17 00:00:00 2001 From: Shubhransh Gupta <54713516+shubhransh-gupta@users.noreply.github.com> Date: Fri, 28 Aug 2026 21:33:54 +0530 Subject: [PATCH] Mark mutating partition functions as @discardableResult (#67) --- Guides/Partition.md | 3 +++ Sources/Algorithms/Partition.swift | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/Guides/Partition.md b/Guides/Partition.md index 54678aa3a..4bfea2268 100644 --- a/Guides/Partition.md +++ b/Guides/Partition.md @@ -63,15 +63,18 @@ The `partitioningIndex(where:)` method is available on any `Collection` type. ```swift extension MutableCollection { + @discardableResult mutating func stablePartition( by belongsInSecondPartition: (Element) throws -> Bool ) rethrows -> Index + @discardableResult mutating func stablePartition( subrange: Range, by belongsInSecondPartition: (Element) throws -> Bool ) rethrows -> Index + @discardableResult mutating func partition( subrange: Range, by belongsInSecondPartition: (Element) throws -> Bool diff --git a/Sources/Algorithms/Partition.swift b/Sources/Algorithms/Partition.swift index 56fb8412a..647b5a744 100644 --- a/Sources/Algorithms/Partition.swift +++ b/Sources/Algorithms/Partition.swift @@ -22,6 +22,7 @@ extension MutableCollection { /// - Precondition: /// `n == distance(from: range.lowerBound, to: range.upperBound)` @inlinable + @discardableResult internal mutating func stablePartition( count n: Int, subrange: Range, @@ -63,6 +64,7 @@ extension MutableCollection { /// /// - Complexity: O(*n* log *n*), where *n* is the length of this collection. @inlinable + @discardableResult public mutating func stablePartition( subrange: Range, by belongsInSecondPartition: (Element) throws -> Bool @@ -87,6 +89,7 @@ extension MutableCollection { /// /// - Complexity: O(*n* log *n*), where *n* is the length of this collection. @inlinable + @discardableResult public mutating func stablePartition( by belongsInSecondPartition: (Element) throws -> Bool ) rethrows -> Index { @@ -122,6 +125,7 @@ extension MutableCollection { /// /// - Complexity: O(*n*) where n is the length of the collection. @inlinable + @discardableResult public mutating func partition( subrange: Range, by belongsInSecondPartition: (Element) throws -> Bool @@ -166,6 +170,7 @@ extension MutableCollection where Self: BidirectionalCollection { /// /// - Complexity: O(*n*) where n is the length of the collection. @inlinable + @discardableResult public mutating func partition( subrange: Range, by belongsInSecondPartition: (Element) throws -> Bool