[swift-evolution] Proposal: Add a sequence-based initializer to Dictionary
greggwonderly at seqtechllc.com
Mon Jan 8 17:23:20 CST 2018
Okay, that does work for my example. But why wouldn’t the key also be available so that you might be able to have selective handling of first vs last for each key?
> On Jan 8, 2018, at 4:03 PM, Nate Cook <natecook at apple.com> wrote:
> Hi Gregg —
> The Dictionary(_:uniquingKeysWith:) initializer was added for this purpose in Swift 4—please see https://developer.apple.com/documentation/swift/dictionary/2892961-init <https://developer.apple.com/documentation/swift/dictionary/2892961-init>
>> On Jan 8, 2018, at 1:02 PM, Gregg Wonderly via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> In some dictionary implementations, key-value pairs are added with an add() method which disallows duplicate keys to be inserted with a runtime exception. Providing an additional method of set() allows for the ability to ignore duplicate keys so that it feels more like dict[key] = value. It might be interesting to provide this as a selectable behavior within an additional constructor's arguments.
>> Dictionary(allowDuplicate: true, pairs: [("z", 1), ("z", 2), ("z", 3), ("z", 4)]) so that the dictionary behavior remains in line with the compile time checks.
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution