
ADT through the looking glass – lenses, prisms and other optics in Scala - maddening
https://kubuszok.com/2018/adt-through-the-looking-glass/
======
cheriot
I find the Monocle library does a good job of describing the motivation for
type optics: [http://julien-truffaut.github.io/Monocle/](http://julien-
truffaut.github.io/Monocle/)

Where I've used this in real code is via circe-optics (json parsing). An
example: [https://stackoverflow.com/questions/36724068/how-to-
parse-a-...](https://stackoverflow.com/questions/36724068/how-to-parse-a-json-
scala-without-case-classes)

------
lasagnaphil
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)?

~~~
whateveracct
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.

------
emarx
Monocle also ships with the macro annotation _monocle.macros.Lenses_ that cuts
out even more of the boilerplate and works with intellij's autocomplete

    
    
      import monocle.macros.Lenses
    
      @Lenses
      case class Foo(bar: Int)
    
      val x = Foo(1)
      assert(Foo.bar.get(x) == 1)

------
Cobord
[https://arxiv.org/abs/1809.00738](https://arxiv.org/abs/1809.00738) is really
nice for general context. Plus can implement some of these generalizations
from what is already here.

------
sk5t
I like working in Scala quite a bit, but always wince at the "instead of using
threading primitives consider this 10x more exotic immutable approach" lead-
in. Does anyone here really work that way?

~~~
threeseed
Never sure why people talk about concurrency as the number one reason to use
immutable structures.

The main reason is that your code is less buggy and easier to read and
understand as your code base gets larger. You never have to worry if that
variable is being modified somewhere else in your codebase because it simply
isn’t.

------
redfast00
Takes a long time to parse because it the text has a lot of typos.

~~~
bad_user
>> " _Takes a long time to parse because it the text has a lot of typos._ "

Your comment has typos too :-)

~~~
redfast00
Welp, you're right, that was hypocritical of me.

