-
Notifications
You must be signed in to change notification settings - Fork 448
Added documentation and where clause for API uniqued()
#32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
6969b96
Making code readable.
Roshankumar350 91f56a5
Added documentation
Roshankumar350 955885f
Added documentation
Roshankumar350 5f50298
consistant Indentation
Roshankumar350 725d68b
1. Indentations with two spaces.
Roshankumar350 2270423
Indentations with two spaces for functions.
Roshankumar350 38bd0ab
Example that demonstrates the uniqued(on:) method.
Roshankumar350 5779714
Addressing comment
Roshankumar350 7d60b3c
Reverting lateral change.
Roshankumar350 8ed7a50
Reverting lateral change
Roshankumar350 8c4ad09
Addressing comment.
Roshankumar350 38f6253
minor correction.
Roshankumar350 51e0ecf
Addressing feedback.
Roshankumar350 56d50c9
Addressing feedback.
Roshankumar350 723f02e
Addressing feedback.
Roshankumar350 511fffa
Spacing
Roshankumar350 c2ee769
spacing
Roshankumar350 14e24eb
Addressing feedback.
Roshankumar350 ee7ae20
Merge branch 'main' into Readability
Roshankumar350 acfbe3e
Making code readable.
Roshankumar350 f1bd757
Merge branch 'Readability' of https://github.com/Roshankumar350/swift…
Roshankumar350 2bee012
Addressing feedback.
Roshankumar350 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,16 @@ | |
|
||
extension Sequence where Element: Hashable { | ||
/// Returns an array with only the unique elements of this sequence, in the | ||
/// order of the first occurence of each unique element. | ||
/// order of the first occurrence of each unique element. | ||
/// | ||
/// let animals = ["dog", "pig", "cat", "ox", "dog", "cat"] | ||
/// let uniqued = animals.uniqued() | ||
/// print(uniqued) | ||
/// // Prints '["dog", "pig", "cat", "ox"]' | ||
/// | ||
/// - Returns: An array with only the unique elements of this sequence. | ||
/// . | ||
/// - Complexity: O(*n*), where *n* is the length of the sequence. | ||
@inlinable | ||
public func uniqued() -> [Element] { | ||
uniqued(on: { $0 }) | ||
|
@@ -24,8 +33,26 @@ extension Sequence where Element: Hashable { | |
|
||
extension Sequence { | ||
/// Returns an array with the unique elements of this sequence (as determined | ||
/// by the given projection), in the order of the first occurence of each | ||
/// by the given projection), in the order of the first occurrence of each | ||
/// unique element. | ||
/// | ||
/// This example finds the elements of the `animals` array with unique | ||
/// first characters: | ||
/// | ||
/// let animals = ["dog", "pig", "cat", "ox", "cow", "owl"] | ||
/// let uniqued = animals.uniqued(on: {$0.first}) | ||
/// print(uniqued) | ||
/// // Prints '["dog", "pig", "cat", "ox"]' | ||
/// | ||
/// - Parameter projection: A closure that transforms an element into the | ||
/// value to use for uniqueness. If `projection` returns the same value | ||
/// for two different elements, the second element will be excluded | ||
/// from the resulting array. | ||
/// | ||
/// - Returns: An array with only the unique elements of this sequence, as | ||
/// determined by the result of `projection` for each element. | ||
/// | ||
/// - Complexity: O(*n*), where *n* is the length of the sequence. | ||
@inlinable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don’t think this was rebased correctly. These annotations shouldn’t be deleted. |
||
public func uniqued<Subject: Hashable>( | ||
on projection: (Element) throws -> Subject | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's give an introduction to this example, as well: