Just gonna put this out there: Scala is full of these scenarios where very small changes to the code have disproportionately large changes to the outcome. It&#x27;s one of the reasons I&#x27;m really not a fan of the language. There are so many features that are mentioned in the literature and lore that you have to learn to not use, for fear of pervasive performance penalties.<p>This is a great example. I&#x27;ve done a lot of Scala and o found the original version very obvious to read, but only experience tells me why the compiler can&#x27;t make it efficient. Your version is not really worse in any way, but I think it&#x27;s fair to say that it shouldn&#x27;t be obvious to everyone why one is suboptimal at first glance.