[swift-evolution] Proposal: Allow operators to have parameters with default values
brent at architechies.com
Sat Nov 4 01:55:26 CDT 2017
> On Nov 2, 2017, at 7:05 PM, Xiaodi Wu via swift-evolution <swift-evolution at swift.org> wrote:
> Firstly, because for the proposed use case it's not a "default" parameter in that it's not overridable: you can't actually pass another argument.
Sure you can. Remember, you can call an operator with function-call syntax:
We could allow you to specify the non-default parameters when you need to using this syntax:
// Normal use:
value !! MyError.missingValue
// With defaulted parameters changed:
(!!)(value, MyError.missingValue, file: someFile, line: someLine)
We could also—as part of a separate proposal, perhaps in a future version of Swift—explore a more elegant syntax for adding options to operator calls. This could be useful for things like string comparisons where you need to decide whether a comparison should be locale-aware, case-sensitive, etc.
// Strawman syntax of possible future expansion:
value !! MyError.missingValue #(file: someFile, line: someLine)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution