Some thoughts after reviewing it a second time:
I am not sure I like having global functions first(_:_:) and last(_:_:). Would
it be possible to default the closure to do what last(_:_:) would do? I'm
assuming the most popular thing to do is to have the values from the second
dictionary prevail.
// These two would be equivalent to passing last(_:_:) function
let newDict = dict1.merged(with: dict2)
let newDict = dict1.merged(with: dict2) { $1 }
If someone wanted to do what first(_:_:) would do, or some other algorithm then
it would be quite simple, wouldn't it? For example:
// This would be equivalent to passing in the first(_:_) function
let newDict = dict1.merged(with: dict2) { $0 }
// Combine values of common keys by adding them
let newDict = dict1.merged(with: dict2) { $0 + $1 }
> On Apr 1, 2017, at 3:58 PM, Nate Cook via swift-evolution
> <[email protected]> wrote:
>
> Yep, here it is -- didn't realize the length would cause such problems!
>
> https://gist.github.com/natecook1000/4bd8f20736eb99ed3c5a4cdcc41e9a5f
> <https://gist.github.com/natecook1000/4bd8f20736eb99ed3c5a4cdcc41e9a5f>
>
> Nate
>
>> On Apr 1, 2017, at 12:01 PM, Jason Gregori via swift-evolution
>> <[email protected] <mailto:[email protected]>> wrote:
>>
>> I really like the merging methods and have already needed to write my own.
>> Zach, do you mind showing a comparison of what you're thinking?
>>
>> Nate, do you mind throwing this up in a gist or something? My email client
>> isn't letting me see the whole thing.
>>
>> Thanks,
>> Jason
>>
>>
>> On Fri, Mar 31, 2017 at 11:52 AM Zach Waldowski via swift-evolution
>> <[email protected] <mailto:[email protected]>> wrote:
>> Snipped quoted proposal so as to not break the mailing list… By and large,
>> I'm in favor. I like the potential for bringing up Dictionary and Set up to
>> the implementation quality of Array and String.
>>
>> I don't think `init(merging:resolvingCollisionsWith:)` et al hold their
>> weight for inclusion in the language, unless some notable optimization
>> opportunity can be surfaced out of it. Users frustrated at the lack of a
>> `merge` in Swift want it to be opinionated and "just do the right thing,"
>> i.e., the same way as whatever other language they most recently used. A
>> properly annotated and indented-to-be-beautiful use of the closure-based
>> version will take up the same amount of code as doing the merge by hand with
>> your custom condition.
>>
>> Sincerely,
>> Zachary Waldowski
>> [email protected] <mailto:[email protected]>
>>
>> _______________________________________________
>> swift-evolution mailing list
>> [email protected] <mailto:[email protected]>
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>> <https://lists.swift.org/mailman/listinfo/swift-evolution>
>> _______________________________________________
>> swift-evolution mailing list
>> [email protected] <mailto:[email protected]>
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>
> _______________________________________________
> swift-evolution mailing list
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution