kenbot / goggles

Pleasant, yet principled Scala optics DSL
MIT License
195 stars 7 forks source link

Support for successive or nested modifications #13

Open kenbot opened 7 years ago

kenbot commented 7 years ago

If we have multiple changes to make to a structure, how can we perform them all without it looking terrible?

val game1 = set"$game.currentLevel.player.health" := 100
val game2 = set"$game1.currentLevel.player.ammo" := 70
val game3 = set"$game2.currentLevel.player.status" = Status.Alive
...

or nested:

set"${set"${set"$game.currentLevel.player.status" = Status.Alive}.currentLevel.player.ammo" := 70}.currentLevel.player.health" := 100

Ew.

But how to do this? A 2d syntax?

val game1 = set"""$game.currentLevel.player.health
                 |                         .ammo
                 |                         .status""" = (100,70,Status.Alive)

That's really weird though. Maybe using the tuple syntax suggested in #10?

set"""$game.currentLevel.player.(health, ammo, status)" := (100, 70, Status.Alive)

This might not be powerful enough though. What do other Lens implementations do? Haskell? Is this needed at all?