kenbot / goggles

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

add syntax for composePrism GenPrism #32

Closed julien-truffaut closed 7 years ago

julien-truffaut commented 7 years ago
case class Foo(i: Int, bar: Bar)
sealed trait Bar
case class Bazz(b: Boolean) extends Bar
case class Buzz(s: String) extends Bar

val foo = Foo(2, Buzz("Hello"))

set"$foo.bar.as[Buzz].s" := "World"
kenbot commented 7 years ago

Thanks for the suggestion! I did think of this one. It has some disadvantages:

I feel there is a bit of a trap with using forms that have a Scala-only intuition - users may naturally expect other Scala features to work, and be surprised when they don't. It may lead to feature-pressure to reimplement half of scalac in the macro, which I really want to avoid. For instance, this is why I used the mainstream notation [...] for indexing rather than the Scala usage (...). I think this applies to square-brackets-as-type-annotations too, apart from the confusion introduced by an overloaded meaning.

The other thing is that there is no need to represent all of Monocle's features in Goggles; ultimately it's very easy to drop in Monocle optics directly, in this case say, from @GenPrisms. So we don't need to rush to introduce syntactic features that would require relaxing the other goals of the project.

kenbot commented 7 years ago

11 is the open issue for named Prism support, we're better discussing the syntax there.

julien-truffaut commented 7 years ago

Sorry I missed #11 and thanks for your detailed arguments. I agree we shouldn't rush adding something that will be a nightmare to maintain. I was mostly suggesting that it would be great to have a short syntax to support both Product and Coproduct