>> Interesting, but I’m unsure if all of it is significantly better than just
>> using the guard that is effectively inside of the operator/func that is
>> being proposed:
>>
>> guard let value = Int("NotANumber") else { throw
>> InitializerError.invalidString }
>>
>
> That is a pretty damn compelling argument.
For some cases, yes. For others…
myInt = Int("NotANumber") ?? throw InitializerError.invalidString
On the other hand, all we really need is a generalized "noneMap" function
marked as rethrowing, which can serve multiple purposes.
myOtherInt = Int("NotANumber").noneMap(arc4random)
myInt = try Int("NotANumber").noneMap { throw
InitializerError.invalidString }
On the gripping hand: I think this is only a problem because `throw` is a
statement, not an expression. Could it be changed to be an expression with an
unspecified return type? I believe that would allow you to simply drop it into
the right side of a ?? operator, and anywhere else you might want it (boolean
operators, for instance).
--
Brent Royal-Gordon
Architechies
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution