Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Focus] add as for enumerations #1028

Closed
julien-truffaut opened this issue Feb 8, 2021 · 1 comment
Closed

[Focus] add as for enumerations #1028

julien-truffaut opened this issue Feb 8, 2021 · 1 comment
Labels
3.x Next major version

Comments

@julien-truffaut
Copy link
Member

julien-truffaut commented Feb 8, 2021

sealed trait User {
  def id: Long
}

case class Reader(id: Long, isPremium: Boolean) extends User
case class Editor(id: Long, favoriteFont: String) extends User

Focus[User](_.as[Reader])
// res: Prism[User, Reader]

Focus[User](_.as[Reader].isPremium)
// res: Optional[User, Boolean]

Operator to generate a Prism based on a type-cast.

I'm pretty sure that any type-cast gives us a Prism, so we shouldn't need to limit it to sealed hierarchies or enums.

@julien-truffaut julien-truffaut added the 3.x Next major version label Feb 8, 2021
@julien-truffaut julien-truffaut mentioned this issue Feb 8, 2021
7 tasks
@julien-truffaut julien-truffaut changed the title as[Foo] DSL operator for Prisms [Focus] add as for enumerations Feb 8, 2021
@kenbot
Copy link
Collaborator

kenbot commented Feb 11, 2021

Given that this is a useful enough feature to have a privileged syntax in Focus, it's worth considering whether it should also be a Monocle operator satisfying Focus[Foo](_.bar.as[Baz]) == Focus[Foo](_.bar).as[Baz]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Next major version
Projects
None yet
Development

No branches or pull requests

2 participants