Skip to content

Instantly share code, notes, and snippets.

@wyager
Created October 14, 2017 18:43
Show Gist options
  • Save wyager/7c071b0e408fba7d77d15533ca0fe264 to your computer and use it in GitHub Desktop.
Save wyager/7c071b0e408fba7d77d15533ca0fe264 to your computer and use it in GitHub Desktop.
import qualified Control.Lens as L
import qualified Control.Lens.Prism as LP
import Data.Semigroup ((<>))
foo :: (b1 -> t) -> (b2 -> t) -> (s -> Either t a1) -> (s -> Either t a2) -> ((Either b1 b2 -> t), (s -> Either t (Either a1 a2)))
foo inj1 inj2 proj1 proj2 = (either inj1 inj2, \s -> (Left <$> proj1 s) <> (Right <$> proj2 s))
foo' :: L.Prism s t a1 b1 -> L.Prism s t a2 b2 -> L.Prism s t (Either a1 a2) (Either b1 b2)
foo' p j = uncurry LP.prism $ LP.withPrism p (\inj1 proj1 -> L.withPrism j (\inj2 proj2 -> foo inj1 inj2 proj1 proj2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment