jvliwanag (3) [Avatar] Offline
Some parts of the sample code leads to breaking referential transparency. For instance:

* Usage of `today`
* Usage of scala.util.Random and accessing the repository to generate an ID

Arguably, breaking referential transparency seems to make the code simpler. But in what cases would it be justifiable to break referential transparency?
Debasish Ghosh (116) [Avatar] Offline
Agreed .. those are for simplicity and you can very well replace them with RT versions. But, as you rightly said, it will make implementations complex and you can question the perceived value that it adds. Of course with Haskell you will be forced to do it as the type system will not allow you otherwise.

Regarding breaking RT, I usually follow the principle that an API has to be RT. There can be mutation as part of the implementation. But so long I have an RT API, it's fine. In fact there are many instances where mutation is required in the implementation for performance reasons. But it never leaks out in the API.