-
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
Conversation
uniqued()
Good catch on the typo!
Note that the code style involves indentations with two spaces, and also wrapping to 80 columns on each line. Sentences end with a period. |
2. Wrapping to 80 columns on each line.
Sources/Algorithms/Unique.swift
Outdated
/// order of the first occurrence of each unique element. | ||
/// | ||
/// In this example, `uniqued()` is used to include only names which are | ||
/// unique |
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.
Thanks, the formatting is now mostly consistent. Make sure to include periods at the end of sentences, like here (also elsewhere). There is still another closing brace that is incorrectly indented. There are also several places where you have two consecutive spaces in the comment or the code; please make sure to remove them. There are also places where there are missing spaces after punctuation: please make sure to add them.
A more general comment here: I don’t think it adds anything to describe the example here by saying that uniqued
makes the array unique. I think this line could be removed.
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.
Thanks for filling out this documentation, @Roshankumar350! A few notes below for you.
Sources/Algorithms/Unique.swift
Outdated
/// unique element. | ||
/// | ||
/// let animals = ["dog", "pig", "cat", "ox", "dog","cat"] | ||
/// let uniqued = animals(on: { $0.first }) |
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.
This does not compile.
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.
Addressed and tested the same example on compiler.
Sources/Algorithms/Unique.swift
Outdated
/// let animals = ["dog", "pig", "cat", "ox", "dog","cat"] | ||
/// let uniqued = animals(on: { $0.first }) | ||
/// print(uniqued) | ||
/// // Prints "["dog", "pig","cat", "ox"]" |
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.
/// // Prints "["dog", "pig","cat", "ox"]" | |
/// // Prints '["dog", "pig", "cat", "ox"]' |
Although the output depends on what the projection chosen for this example is.
Sources/Algorithms/Unique.swift
Outdated
/// | ||
/// - Parameter projection: A projecting closure. `projection` accepts an | ||
/// element of this sequence as its parameter and returns a projected | ||
/// value of the same type. |
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.
/// value of the same type. | |
/// value of the same type. |
This description is true, but it’s also just describing the type signature in words. But what are the semantics expected of this closure? That should be documented here.
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.
Added constraint of "Hashable" element
Sources/Algorithms/Unique.swift
Outdated
@@ -42,14 +42,14 @@ extension Sequence { | |||
/// by the given projection), in the order of the first occurrence of each | |||
/// unique element. | |||
/// | |||
/// let animals = ["dog", "pig", "cat", "ox", "dog","cat"] | |||
/// let uniqued = animals(on: { $0.first }) | |||
/// let animals = ["dog", "pig", "cat", "ox", "dog", "cat"] |
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.
This example doesn't really demonstrate the role of the 'projection' closure. If you want to stick to the projection $0.first
, I'd suggest something like:
/// let animals = ["dog", "pig", "cat", "ox", "dog", "cat"] | |
/// let animals = ["dog", "pig", "cat", "ox", "cow", "owl"] |
Sources/Algorithms/Unique.swift
Outdated
/// | ||
/// - Parameter projection: A projecting closure. `projection` accepts an | ||
/// element of this sequence as its parameter and returns a projected | ||
/// value of the same type. | ||
/// value of the same type having constraint `Hashable`. |
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.
The addition about 'Hashable' is useful, but the first part of this line is not correct: the projected value does not need to be of the same type.
But moreover, even when corrected, this statement is still describing the type of the parameter in words, which is not necessary and doesn't add to a user's understanding, assuming that they know how to read Swift type signatures. The challenge here is to teach the user why and how to use a projection function to determine uniqueness.
Sources/Algorithms/Unique.swift
Outdated
/// - Parameter projection: A projecting closure. `projection` accepts an | ||
/// element of this sequence as its parameter which is having the type of | ||
/// projecting element and returns a projected value that may have the same | ||
/// type having constraint `Hashable`. |
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.
@natecook1000 Do you have suggestions of how to approach describing this parameter?
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.
Getting close, @Roshankumar350!
Sources/Algorithms/Unique.swift
Outdated
/// - Parameter projection: A projecting closure. `projection` accepts an | ||
/// element of this sequence as its parameter which is having the type of | ||
/// projecting element and returns a projected value that may have the same | ||
/// type having constraint `Hashable`. |
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.
How about this?
/// - Parameter projection: A projecting closure. `projection` accepts an | |
/// element of this sequence as its parameter which is having the type of | |
/// projecting element and returns a projected value that may have the same | |
/// type having constraint `Hashable`. | |
/// - 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. |
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.
@natecook1000 Thanks for forward thinking.
/// let animals = ["dog", "pig", "cat", "ox", "cow", "owl"] | ||
/// let uniqued = animals.uniqued(on: {$0.first}) |
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:
/// let animals = ["dog", "pig", "cat", "ox", "cow", "owl"] | |
/// let uniqued = animals.uniqued(on: {$0.first}) | |
/// 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 }) |
This looks great! Final step: looks like there's a conflict between this change and the main branch, and the revisions here are best as one commit instead of 18. So please squash and rebase this PR. Here's an introductory guide to doing that from the folks at Servo: https://github.com/servo/servo/wiki/Beginner%27s-guide-to-rebasing-and-squashing |
*Added documentation *Added documentation *consistant Indentation *1. Indentations with two spaces. *2. Wrapping to 80 columns on each line. *Indentations with two spaces for functions. *Example that demonstrates the uniqued(on:) method. *Addressing comment *Reverting lateral change. *Reverting lateral change *Addressing comment. *minor correction. *Addressing feedback. *Addressing feedback. *Addressing feedback. *Spacing *spacing *Addressing feedback.
…-algorithms into Readability Merged
/// unique element. | ||
@inlinable |
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.
I don’t think this was rebased correctly. These annotations shouldn’t be deleted.
Looks great, @Roshankumar350 — thanks for sticking with this! 🎉 |
Problem:
* A quick look up for the API named
uniqued()
with example associated with it was missing.* API named
uniqued()
while enumerating each element was checking anif
condition.Solution:
* API documentation added to address the same.
*
where
clause added for the sameChecklist