Skip to content

Instantly share code, notes, and snippets.

@benkolera
Created February 10, 2014 12:24
Show Gist options
  • Save benkolera/8914951 to your computer and use it in GitHub Desktop.
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).
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