Hacker News new | ask | show | jobs
by lasagnaphil 2739 days ago
I mainly program in low-level imperative languages (mostly C/C++), and occasionally dabbled in some functional languages (like Ocaml and Elm). But I don’t really understand why you would need such a convoluted system to get/mutate some values in a data structure in Scala. Doesn’t Scala allow mutability throughout its language already (unlike Haskell)?
3 comments

Lens doesn't give you mutability. It gives you operations that look like mutations but are still operations on immutable data structures. And that is where the value lies.
But I don’t really understand why you would need such a convoluted system to get/mutate some values in a data structure in Scala.

It allows you to work with deep data structures in a safe immutable way.

Scala is a nice language for working with data, the standard library, techniques such as lenses and ecosystems such as Spark all contribute to this.

Scala, like, enables and encourages immutability, while making regular Java stuff and practices also entirely available (excepting a few Java varargs situations that perplex Scala's notion of arity). This article is, sort of, related to ideas on avoiding mutability anyway.