-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Improve documentation for compactMapValues() of Dictionary #18547
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
Improve documentation for compactMapValues() of Dictionary #18547
Conversation
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 noticing this, @Moximillian! I have one change request in the abstract.
stdlib/public/core/Dictionary.swift
Outdated
/// Returns a new dictionary containing the keys of this dictionary with the | ||
/// values transformed by the given closure. | ||
/// Returns a new dictionary containing only keys that have non-`nil` value | ||
/// as the result from the transform by the given closure. |
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.
Could this say "...only the key-value pairs that have non-nil
values..."?
59b2d80
to
612a820
Compare
@natecook1000: abstract updated, and commits squashed |
@natecook1000 any guess on what the complexity notation should be for this method? O(m+n) like in the compactMap? mapValues() is also missing complexity notation. |
Right — |
612a820
to
29552cf
Compare
@natecook1000 I have added the complexity notations as well. |
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.
Looks great!
@swift-ci Please smoke test and merge |
/// Returns a new dictionary containing only the key-value pairs that have | ||
/// non-`nil` values as the result from the transform by the given closure. | ||
/// | ||
/// Use this method to receive a dictionary of nonoptional values when your |
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 should it be "nonoptional" or "non-optional"? I would vote for the latter, since it's a little easier to parse. Just wondering, no big deal.
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.
"nonoptional" is the one we use elsewhere, currently — updating the other uses over in #18263. Thanks!
@swift-ci Please smoke test |
The recently added compactMapValues -method in stdlib's Dictionary type copies its documentation from mapValues, which is not accurate description of the method.
Using compactMap in SequenceAlgorithms.swift as an example, rewrite the the documentation for compactMapValues and provide an example of the usage (vs. mapValues).