Re: [swift-evolution] Optional dictionary subscripts

2015-12-23 Thread Brent Royal-Gordon via swift-evolution
> I think this would be the standard syntax: > > if let value = key.map({ dict[$0] }) { > > } In this case, I think you actually want a flatMap, to merge the two `nil` cases instead of nesting them. if let value = key.flatMap({ dict[$0] }) { } I wish that

Re: [swift-evolution] Optional dictionary subscripts

2015-12-22 Thread Félix Cloutier via swift-evolution
if let value = map(key) { dict($0) } Félix > Le 22 déc. 2015 à 13:00:45, Erica Sadun via swift-evolution > a écrit : > > if let key = key, value = dict[key] { >...whatever... > } > > seems to work fine without introducing a new construct > > -- E, waving hi to

Re: [swift-evolution] Optional dictionary subscripts

2015-12-22 Thread Dave Abrahams via swift-evolution
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 > wrote: > > if let value = map(key) { dict($0) } > > Félix > >> Le 22 déc. 2015 à 13:00:45, Erica Sadun via

Re: [swift-evolution] Optional dictionary subscripts

2015-12-22 Thread Erica Sadun via swift-evolution
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 > wrote: > > This isn’t the most compelling of ideas but a

[swift-evolution] Optional dictionary subscripts

2015-12-22 Thread John Holdsworth via swift-evolution
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