Skip to content

Add uniqued(on:uniquingWith:) and uniqued(uniquingWith:) conflict-resolving overloads - #290

Open
shubhransh-gupta wants to merge 1 commit into
apple:mainfrom
shubhransh-gupta:feature/uniqued-combining
Open

shubhransh-gupta wants to merge 1 commit into
apple:mainfrom
shubhransh-gupta:feature/uniqued-combining

Conversation

@shubhransh-gupta

Copy link
Copy Markdown

Summary

Resolves #188.

Currently, Sequence.uniqued(on:) only keeps the first occurrence for duplicate keys and drops subsequent elements without allowing custom conflict resolution. This PR adds conflict-resolving overloads to Sequence:

  • uniqued(on:uniquingWith:)
  • uniqued(uniquingWith:) (for Sequence where Element: Hashable)

These methods maintain the existing Dictionary(_:uniquingKeysWith:) and keyed(by:resolvingConflictsWith:) semantics by calling combine with the current accumulated element and the newly encountered element, preserving the relative index positioning of the first occurrence.

Changes

  • Added uniqued(on:uniquingWith:) and uniqued(uniquingWith:) in Sources/Algorithms/Unique.swift.
  • Updated documentation and API specifications in Guides/Unique.md.
  • Added unit tests in Tests/SwiftAlgorithmsTests/UniqueTests.swift covering collision resolution, order preservation, empty sequences, and throwing closures.

Checklist

  • Code style follows the rest of the project
  • Unit tests added and passing (226 tests passed)
  • Documentation updated in Guides/Unique.md

@kateway0694-lab kateway0694-lab left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@caitlinbrahler

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.

uniqued(on:) is missing a uniquingWith overload.

2 participants