So there’s been quite a few comments along the lines of “this only works for Options”, “this privileges Option”, and “for -comprehensions are more general, this is only a special case”.
Options are special, they should be special, and they are a case worth specializing for:
- They are how we deal with
null. -
0..1is different in kind not degree from0..N, soforcomprehensions are not more general, they are different.
Options are pervasive in Scala, yet their usage is still cumbersome.
Adding if-comprehensions and def foo(s: String?) callable with foo(myString) and foo(myStringOpt: _?) as I suggested years ago (please ignore the elvis operator second part of that suggestion) would go a long way towards making Options in Scala more ergonomic.
And that is a goal worth pursuing.