@Qbyte This is brilliant, thank you. To be honest I think this is better than the requested feature, and I’m (almost) satisfied with it. I think it’s better to have to mark the modified function call with try?
than to simply pass in optional parameters with an easy to miss question mark. Additionally, it of course already follows the behavior of throwing expressions as per @mayoff's request, since it is one. My only issue with this is the pipe character |
. I like having to write try?
but I would prefer to be able to use just a postfix question mark for the arguments. For now however, I can live with the pipe. Since posting about this feature I’ve suddenly noticed many more use cases for it in my work, and I’ve been dismayed each time as I realize that it’s not currently supported - but you’ve just given me a solution that I consider viable, so thank you again.
Update of thoughts:
On the other hand, I realize that in reality this operator you've invented is fundamentally different from the unwrapping post-fix operator we're used to (?
) - this operator is the Throwing Unwrap Operator, and rather than abort the operation silently upon encountering nil
like the normal Unwrap Operator does, it aborts loudly and forces you to handle it as a thrown error. Therefore, I'm considering retracting even my qualm with the pipe character. I'm not sure that I stand by it as the best spelling, but I no longer think that a simple ?
would be the better option, because this is a fundamentally different type of unwrap operation and should not be invoked identically.
Update on the update:
After relearning the rules on operator naming I've realized that I don't think there's a better option than what @Qbyte has suggested. The allowed operator characters are /
, =
, -
, +
, !
, *
, %
, <
, >
, &
, |
, ^
, ?
, and ~
, and postfix operators can't begin with either ? or !. It seems clear to me that the operator should be no more than 2 characters, and it also seems clear to me that there should be a question mark involved, since this is an unwrapping operation. We aren't allowed to make the postfix ?
operator again, so this suggests that we must have exactly two characters in this operator, so that one can be a ?
and the other can distinguish it from the built-in single ?
operator. Since postfix operators can't start with a ?
or an !
, the question mark must be the second character. Therefore, our range of possible operators has gotten quite small. All we can do is pick one of the operator characters besides ?
and !
to be the first character of our _?
operator. Looking at the options, I now see that |
feels like the least weird one to me, so that's what I'll use for now.