[swift-evolution] Optional dictionary subscripts

Dave Abrahams dabrahams at apple.com
Tue Dec 22 19:43:03 CST 2015


I think this would be the standard syntax:

if let value = key.map({ dict[$0] }) {

}

> On Dec 22, 2015, at 10:33 AM, Félix Cloutier via swift-evolution <swift-evolution at swift.org> wrote:
> 
> if let value = map(key) { dict($0) }
> 
> Félix
> 
>> Le 22 déc. 2015 à 13:00:45, Erica Sadun via swift-evolution <swift-evolution at swift.org> a écrit :
>> 
>> if let key = key, value = dict[key] {
>>   ...whatever...
>> }
>> 
>> seems to work fine without introducing a new construct
>> 
>> -- E, waving hi to John 
>> 
>> 
>>> On Dec 22, 2015, at 4:37 AM, John Holdsworth via swift-evolution <swift-evolution at swift.org> wrote:
>>> 
>>> This isn’t the most compelling of ideas but a couple of times I’ve found myself writing:
>>> 
>>> if let value = key != nil ? dict[key] : nil {…
>>> 
>>> and was wondering if the syntax could be:
>>> 
>>> if let value = dict[key?] {…
>>> 
>>> The key for dictionaries could be made optional in stdlib but this is probably best implemented in the compiler for safety.
>>> 
>>> Cheers
>>> _______________________________________________
>>> swift-evolution mailing list
>>> swift-evolution at swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-Dave





More information about the swift-evolution mailing list