From 3061c58131470ab700184835ea19e669e80545ef Mon Sep 17 00:00:00 2001 From: Aditya Singh Date: Fri, 29 May 2026 00:42:58 -0700 Subject: [PATCH] Add @discardableResult to mutating partition methods The mutating partition/stablePartition methods return the index of the first element of the second partition. That index is often not needed at the call site (e.g. bringForward(elementsSatisfying:) from Embracing Algorithms, WWDC 2018), which produced a spurious 'result of call is unused' warning. Mark these methods @discardableResult so callers may ignore the returned index without a warning. Fixes #67 --- Sources/Algorithms/Partition.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sources/Algorithms/Partition.swift b/Sources/Algorithms/Partition.swift index 56fb8412..079506d1 100644 --- a/Sources/Algorithms/Partition.swift +++ b/Sources/Algorithms/Partition.swift @@ -63,6 +63,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 +88,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 +124,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 +169,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