On 27/07/2020 02:50, Mikko Värri wrote:
Earlier emails talked about supporting full closure syntax for <expr2>. Is this still included? If so, the implicit variable would naturally be the closure parameter (`it` usually). Would it make sense to use the `it` name even in "plain expression" form, instead of `_` or `$`? To me, `_` denotes an ignored parameter, and `$` looks like something internal added by some AST transform.
Was thinking the same thing with regards to "it" being the Groovy default name for the implicit parameter.
(Adding "$" here just for this would seem a bit heavy handed to me.)
Is the short form short for avoiding null return value, or short for Groovy truthiness check? All the use cases shown are for the former, but it feels like the latter (b/c it is short for an if clause).
Again thinking the same, but if it were Grooyv truth, it would evidently prohibit using the proposed syntax for methods with boolean return types, String|s, collections/maps, any class that implements asBoolean(), ... So one really would have no choice here, same as in the case of Groovy's safe dererencing operator, which also uses non-nullness, not Groovy-truth.
Introducing a notation to purely express non-nullness in Groovy, e.g. using a double question mark would make this clear (but alas would leave the safe dererencing operator the odd man out):
return?? x // Returns x iff x != null final y = x ??: nonNullFallback // assigns x to y iff x != null return? x // Returns x iff x is Groovy-true final y = x ?: nonNullFallback // assigns x to y iff x is Groovy-true Cheers, mg