Monocle: Optics Library for Scala
optics.dev
Monocle: Optics Library for Scala
1–10 of 70 posts
Re: Monocle: Optics Library for Scala
#2Re: Monocle: Optics Library for Scala
#3Re: Monocle: Optics Library for Scala
#4Re: Monocle: Optics Library for Scala
#5I haven't encountered this pattern before. Is there some more information on what problems this is designed to solve?
Re: Monocle: Optics Library for Scala
#6Re: Monocle: Optics Library for Scala
#7Also, the original strong need for immutable data in the first place is safety under concurrency and parallelism?
Re: Monocle: Optics Library for Scala
#8Re: Monocle: Optics Library for Scala
#9So behind the scenes, every one of those statements will make a whole new user object with a whole new address object so that it remains immutable? And whether that will actually have any real-world performance impact is I guess entirely situational. Still, what happens if you do that with a big object graph? Also, the original strong need for immutable data in the first place is safety under concurrency and parallel…
Of course, copying a case class in order to change a field likely does require a full copy of the object, though since this is the JVM, things like strings can be shared between them.
Ultimately this pattern is... fine. Most uses don't end up caring about the extra overhead vs. that of direct mutation. I don't recall if the Scala compiler does this, but another optimization that can be used is to actually mutate an immutable object when the compiler knows the original copy isn't used anywhere else after the mutation.
> Also, the original strong need for immutable data in the first place is safety under concurrency and parallelism?
That's one of the uses, but multiple ownership in general is another, without the presence of concurrency.
On top of that, there's the general belief (which I subscribe to) that mutation introduces higher cognitive load on someone understanding the code. Immutable data is much easier to reason about.
Re: Monocle: Optics Library for Scala
#10I haven't encountered this pattern before. Is there some more information on what problems this is designed to solve?
The optical analogy comes from how these operations resemble zooming in on structures with a magnifying glass and the entire family of related transformations is called optics.