Questions tagged [monocle-scala]

Monocle is a Lens library, or more generally an Optics library where Optics gather the concepts of Lens, Traversal, Optional, Prism and Iso. Monocle is strongly inspired by Haskell Lens.

Monocle is a Lens library, or more generally an Optics library where Optics gather the concepts of Lens, Traversal, Optional, Prism and Iso. Monocle is strongly inspired by Haskell Lens.

What does it mean?

Optics are a set of purely functional abstractions to manipulate (get, set, modify) immutable objects. Optics compose between each other and particularly shine with nested objects.

Why do I need this?

Scala already provides getters and setters for case classes but modifying nested object is verbose which makes code difficult to understand and reason about.

Github

32 questions
0
votes
1 answer

How to reduce boilerplate with monocle in scala

I've refactored my code for day 12 of advent of code by using monocle, a lens library in scala. Is it possible to improve this code : type Register = String type Mem = Map[String, Int] @Lenses case class State(mem: Mem, pointer: Int) def…
Yann Moisan
  • 8,161
  • 8
  • 47
  • 91
0
votes
1 answer

Using applyOptional in Monocle

I'm trying to figure out how to use applyOptional. I've got this: import monocle.function.all.index import monocle.macros.{GenLens, Lenses} import monocle.std.map._ import monocle.syntax.ApplyOptionalOps._ import monocle.function.Index._ val map:…
A_P
  • 326
  • 1
  • 12
1 2
3