A big part of scala 2.13 goes with the collection redesign. It was decided that the redesigned should be as near as possible than the current collection (see https://groups.google.com/forum/#!msg/scala-debate/Z1YH_0Hgu5A/yqhTddk6AQAJ).
Still, one of the big selling point of the redesigned was that with the new collection, lazy collection and operation fusion should just work (ie: that .view
should be usable, contrary to present situation). In fact, AFAIK, the design is so that immutable collection are view by default and the strict evaluation is forced on operation (https://www.scala-lang.org/blog/2017/11/28/view-based-collections.html).
I would really, really, really love to be able to specify that for all my project, the lazy behavior is the one by default, and the complicated one that makes performance horrible as soon as you have big collections in prod and a couple of filter/map/flatMap/goupBy applied would be the one needing a special word.
I’m in no way a pure FP extremist. I work on Rudder, which as you can see by yourself, is very far from pure FP. But we do use almost only immutable collections, with lots of map/filter/etc on them, because it’s way simpler to understand what’s going on.
But without operation fusion, and collection with some millions of elements, the performance hit is huge on any chain of transformation.
Now, I can try to teach all my colleagues to always ever write view
before any map or for comprehension, but this is extremelly error prone. And really, it’s just the kind of thing that the language handle for you.
And it would make me so sad.
On the other hand, we are totaly ok to make special hand waving when we need a strict semantic for some exceptionnal reason. We even have a couple of arrays lying in the code for some very perf sensitive hot spot. But that’s the exception. Most of the code is boring business code with a O(disk & network access), except when the CPU and the carbage collector go mad for excess of copy of big collection.
All that being said, and even if I know that the default behavior for scala collection won’t change (that was made clear by Martin, several times), can we at least get a compiler option to automatically get lazy collection everywhere? Or even just operation fusion (in fact, I can live with stream and lazylist when I need lazyness beyond the scope of operation fusion, at least if the fusion is between chained app function).
And for the record, as it was asked by @julienrf, I don’t have the least capacity to make a PR for that - but I’m able to open a comment here.
Edit: all that was written with the assumption that View
has operation fusion… But then @julienrf pointed to https://github.com/scala/collection-strawman/pull/144 and now I’m not quite so sure… Has it?