-
Notifications
You must be signed in to change notification settings - Fork 98
Adds key mapping support for use in destination plugins. #38
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
|
||
// MARK: - Helpers | ||
|
||
extension Dictionary where Key == String, Value == Any { | ||
internal func mapKeys(_ keys: [String: String], valueTransform: ((_ key: Key, _ value: Value) -> Any)? = nil) throws -> [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.
Do you need = nil
on there?
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.
Yeah, cuz I want it to be optional. They likely just want to map keys, at which point, the values won't be transformed.
if !(newValue is [Key: Value]), let transform = valueTransform { | ||
// it's not a dictionary apply our transform. | ||
|
||
// note: if it's an array, we've processed any dictionaries inside |
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.
👍🏻
return newValue | ||
}).dictionaryValue | ||
|
||
XCTAssertTrue(output!["AKey1"] as! Int == 11) |
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.
Can we change these to as? so we fail the unit test instead of crash the unit tests?
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 could I guess, though that doesn't really bother me. We'd need to go hit a bunch of other tests as well as that's my MO for unit tests. FORCE UNWRAP ALL THE THINGS!
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.
LGTM -- just some nitpicks
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. Awesome idea.
mapKeys
function to JSON object w/ optional value transform step.