Skip to content

Mark mutating partition functions as @discardableResult - #284

Open
shubhransh-gupta wants to merge 1 commit into
apple:mainfrom
shubhransh-gupta:fix/partition-discardable-result
Open

Mark mutating partition functions as @discardableResult#284
shubhransh-gupta wants to merge 1 commit into
apple:mainfrom
shubhransh-gupta:fix/partition-discardable-result

Conversation

@shubhransh-gupta

Copy link
Copy Markdown

Description

Resolves #67.

Adds @discardableResult to all mutating partitioning methods on MutableCollection (stablePartition(count:subrange:by:), stablePartition(subrange:by:), stablePartition(by:), and partition(subrange:by:)), matching the Swift Standard Library's MutableCollection.partition(by:) (SE-0120) and Rotate.swift in Swift Algorithms.

Detailed Design

When calling in-place partition algorithms, callers often perform the mutation for its reordering effect and do not always require the returned pivot Index. Without @discardableResult, ignoring the return value emits an unnecessary compiler warning (Result of call to 'stablePartition' is unused).

Adding @discardableResult removes this friction without impacting callers that do capture the pivot index.

Checklist

  • I've added at least one test that validates that my change is working, if appropriate
  • I've followed the code style of the rest of the project
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary

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