-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
New dictionary extensions. #193
Conversation
/// SwifterSwift: Return every key of the dictionary as a tuple array. There's no order guaranteed. | ||
/// | ||
/// - Returns: key/value of dictionary as a tuple array. | ||
public var tuples : [(key: Key, value: Value)] { |
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.
We really shouldn't use computed properties for functionality with complexity > O(1)
Codecov Report
@@ Coverage Diff @@
## master #193 +/- ##
==========================================
+ Coverage 92.8% 92.82% +0.01%
==========================================
Files 85 85
Lines 4756 4767 +11
==========================================
+ Hits 4414 4425 +11
Misses 342 342
Continue to review full report at Codecov.
|
/// SwifterSwift: Return every key of the dictionary as a tuple array. There's no order guaranteed. | ||
/// | ||
/// - Returns: key/value of dictionary as a tuple array. | ||
public func tuples() -> [(Key,Value)] { |
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 feel like this extension is not a good fit for SwifterSwift.
It specializes the generic abstraction created by map
-- It is just map { $0 }
/// | ||
/// - Parameter where: condition to evaluate each tuple entry against. | ||
/// - Returns: Filtered key/value of dictionary as a tuple array. | ||
public func tuples(where condition: @escaping ((key: Key, value: Value)) throws -> Bool) rethrows -> [(Key, Value)] { |
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.
Same as above. This is just a wrapper around flatMap
. There isn't much to gain here. Whether you use flatMap
or tuples
you will have to write out the closure. This function is just constricting our return type, essentially, a type constrained flatMap
.
/// | ||
/// - Parameter where: condition to evaluate each tuple entry against. | ||
/// - Returns: Count of entries that matches the where clousure. | ||
public func count(where condition: @escaping ((key: Key, value: Value)) throws -> Bool ) rethrows -> Int { |
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 👍
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.
See comments above
Checklist