I should also say, there's really nothing wrong in just coding the
imperative algorithm in Scala. It's not a sacrilege to use imperative code,
in particular if it's inside a function. Sometimes it's the clearest way to
express things. Many other times it is not.
- Martin Oderksy