The issue of handling missing / alternative values with Option and friends has been a source of disappointment for quite some time, especially if we look at the alternatives other modern languages provide. The community has been throwing libraries and proposals at it (including my own proposal to empower T | Null) but it never felt like we nailed it.
And despite the grass being greener on the neighbours side, IMHO no programming language managed to provide a fully unified and satisfactory solution so far.
This proposal is really refreshing: it’s ergonomic, holistic and innovative. In short, the true spirit of Scala ! And I’m sure it’ll serve as a lighthouse for other languages as has been the case with a several language features in the past.
While we’re at it, we have an opportunity to take some of the best productivity features and sugars programmers love that have proven their worth across popular languages. It’s great that the postfix ? operator has already been proposed, here are some other additions that come to mind:
Feature parity with Option
fold, get, contains, exists, … All the familiar methods we love from Option (and maybe others ? The Rust API could be a good source of inspiration) would make the feature more ergonomic and help with the transition.
?? AKA nullish / nil coalescing operator
A great companion to the ? operator. Languages which have the latter usually provide the former.
def isItGreat(input: String?): String = input ?? "Absolutely!"
Available in JS / TS, Swift, C# and Kotlin (as ?:). Functionally equivalent to getOrElse but shorter and probably clearer.
Aborting to the enclosing function by default
Could we have the best of both worlds ? maybe is great when one needs that flexibility, however the most common case will probably be Rust-like, i.e. aborting to the enclosing function. Would it be feasible / desirable to have that as the default (given that the return type matches) ? This obviously would spare us some ceremony and syntax overhead (especially for one-liner functions) but mostly would make the feature easier and more accessible to beginners.