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

Add .asCase to VariantLens #93

Closed
wants to merge 1 commit into from
Closed

Add .asCase to VariantLens #93

wants to merge 1 commit into from

Conversation

jeffmay
Copy link
Owner

@jeffmay jeffmay commented Feb 4, 2022

  • Add .asCase to VariantLens using shapeless.Typeable

Comment on lines +153 to +157
/**
* Attempt to cast the value of super-type [[B]] as sub-type [[V]] (if possible), otherwise None.
*/
def asCase[V <: B : Typeable]: VariantLens[A, Option[V]] =
lens.copy(get = lens.get.andThen(Typeable[V].cast))
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I should handle multiple cases at once, otherwise, you would be required to use when / then / else and unify the results. A Expr.Match might be a better option... it could also potentially replace the When operator as a more generally useful operator, but each branch has a lens that is applied before any optional condition guard.

@jeffmay jeffmay marked this pull request as draft February 8, 2022 20:13
@jeffmay
Copy link
Owner Author

jeffmay commented Feb 17, 2022

Closing in favor of #95

@jeffmay jeffmay closed this Feb 17, 2022
@jeffmay jeffmay deleted the jeff/v1/asCase branch October 1, 2022 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants