-
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
Create mapping functions for Dictionary #546
Conversation
7dd06af
to
93c8e1b
Compare
…a new `Dictionary`, rather than an `Array`.
93c8e1b
to
fb00a2f
Compare
Generated by 🚫 Danger |
@guykogus This is interesting but I don't like how we're overloading |
Codecov Report
@@ Coverage Diff @@
## master #546 +/- ##
==========================================
+ Coverage 94% 94.01% +<.01%
==========================================
Files 68 68
Lines 2871 2875 +4
==========================================
+ Hits 2699 2703 +4
Misses 172 172
Continue to review full report at Codecov.
|
For me it makes more sense for |
@guykogus I'd be more accepting of |
…mpactMap` functions.
OK, updated the names. |
map
and compactMap
functions for Dictionary
mapKeysAndValues
and compactMapKeysAndValues
functions for Dictionary
mapKeysAndValues
and compactMapKeysAndValues
functions for Dictionary
@guykogus I guess they are over the generic key/value, but the return type is still bound to |
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.
@guykogus Interesting extension, and amazing that you added complexity as well 💯
@omaralbeik I stole the documentation from Apple's docs 😄. The complexity of |
Sorry couldn't be on the discussion 😭 |
I'm a big fan, especially for using dictionaries where the keys are enums that I eventually need to pass as the parameters to an HTTP call, so they need to be converted to their raw values. I feel like there'd be lots of useful scenarios for this... |
🚀
These versions of
map
andcompactMap
return aDictionary
, rather than anArray
.I'm a bit unsure of the function names because of the clash with the built-in
map
andcompactMap
functions.map
seems to prioritise the new function. E.g. instringToInt
is of type[String: Int]
. If you want it to return[(String, Int)]
, as the original function would do, you need to define the type explicitly. I.e.compactMap
actually won't compile in a similar situation because it prioritises the built-in function. E.g.will throw a compilation error because it thinks that the the closure passed to
compactMap
should contain a single argument, it won't accept a tuple. You need to explicitly define it asin order for it to compile and use the new function.
To use the original function you again need to explicitly define the type. I.e.
What do you guys think, should we rename the functions? What names sound good to you?
Checklist