You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using the mutating partitioning functions are useful even when the returned index isn’t used.
The Embracing Algorithms (WWDC 2018) session implements a bringForward(elementsSatisfying:) function on MutableCollection.1 It uses stablePartition(by:) in its implementation, but doesn’t need its return value, resulting in a warning.
Actual behavior
extensionMutableCollection{mutatingfunc bringForward(elementsSatisfying predicate:(Element)->Bool){iflet predecessor =indexBeforeFirst(where: predicate){self[predecessor...].stablePartition(by:{ !predicate($0)}) // ⚠️ Result of call to 'stablePartition(by:)' is unused
}}}
While it could be argued that bringForward(elementsSatisfying:) should return an Index as well, even that return value isn’t always needed to be used and should be marked as @discardableResult.
Checklist
If possible, I've reproduced the issue using the main branch of this package
I can't recall, but I imagine we just followed the precedent set by partition(by:) from the standard library which does not mark its result as a @discardableResult.
While it could be argued that bringForward(elementsSatisfying:) should return an Index as well, even that return value isn’t always needed to be used and should be marked as @discardableResult.
I do think bringForward(elementsSatisfying:) should probably return an Index (one of Alexander Stepanov's API design principles is "don't throw away useful information"), but I agree that should arguably be marked as @discardableResult.
Using the mutating partitioning functions are useful even when the returned index isn’t used.
The Embracing Algorithms (WWDC 2018) session implements a
bringForward(elementsSatisfying:)
function onMutableCollection
.1 It usesstablePartition(by:)
in its implementation, but doesn’t need its return value, resulting in a warning.Actual behavior
Expected behavior
While it could be argued that
bringForward(elementsSatisfying:)
should return anIndex
as well, even that return value isn’t always needed to be used and should be marked as@discardableResult
.Checklist
main
branch of this packageThe text was updated successfully, but these errors were encountered: