Scala has been always known as a language which allows special handling of null values. There is ton of articles regarding Some[T], None, Option[T].
What is most annoying code for me? Null validations, see usual example:
When you start to write save code in the term of fails-as-fast-as-possible, your code, services or even domain model, will be weedy, you will find such boilerplate code at every method because you can’t be sure which parameter supplied someone to you class or method.
Unfortunately Scala has beautiful way how to achieve nice and simple code – without these checks. If you don’t think that null is proper state for your class, just dismiss this option. How to do that?
Well, that’s all. Look at screenshot from my IDE what is about to happen:
Now, if you are sure that you don’t want to allow null value for your entity, you can implement NotNull trait and you can remove many lines from your source code.
I was surprised when I found this trait in scala code, because many tutorials or even famous Scala for the Impatient book does not mention this simple but beautiful piece of code.