Created
February 10, 2014 12:24
-
-
Save benkolera/8914951 to your computer and use it in GitHub Desktop.
Gotta be a better way. Also, PLens feels weird with the setter being an Option (compared to Control.Lens.Prism, at least).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def eitherPLens[X,A,B]( | |
lensLeft: X @?> A , | |
lensRight: X @?> B | |
): X @?> (A \/ B) = PLens.plensg( | |
x => Some( | |
_.fold( lensLeft.setOr( x , _ , x ), lensRight.setOr( x , _ , x) ) | |
), | |
x => lensLeft.get( x ).map( -\/[A](_) ).orElse( | |
lensRight.get( x ).map( \/-[B](_) ) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment