Skip to content

Add @discardableResult to mutating partition methods#274

Open
adityasingh2400 wants to merge 1 commit into
apple:mainfrom
adityasingh2400:fix-issue-67
Open

Add @discardableResult to mutating partition methods#274
adityasingh2400 wants to merge 1 commit into
apple:mainfrom
adityasingh2400:fix-issue-67

Conversation

@adityasingh2400
Copy link
Copy Markdown

Problem

The mutating partition(by:) / stablePartition(by:) family returns the index of the first element in the second partition, but the methods are not marked @discardableResult. Callers who only want the in-place partitioning side effect and don't need the pivot index get an unavoidable "result of call is unused" warning, as requested in #67.

Change

Add @discardableResult to the four mutating partition methods on MutableCollection (and the BidirectionalCollection overload). @discardableResult is purely additive and source-compatible: it only suppresses the unused-result warning for callers that ignore the return value, and changes no runtime behavior. Callers who use the returned index are unaffected.

Verification

swift build and swift test pass. No behavioral change; the attribute only affects unused-result diagnostics.

Fixes #67.

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 apple#67
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Partition: Make mutating functions return @discardableResult

1 participant