{-# LANGUAGE Rank2Types #-}
module Control.Lens.SplitMorphism (
reverseEpi
, reverseMono
, composeSplitEpiMono
, composeSplitEpiPrism
, composeSplitMonoEpi
, epiAsWedge
, monoAsWedge
) where
import Control.Lens
import Control.Lens.Format (Format (..))
import Control.Lens.SplitEpi (SplitEpi (..))
import Control.Lens.SplitMono (SplitMono (..))
import Control.Lens.Wedge (Wedge (..))
reverseEpi :: SplitEpi a b -> SplitMono b a
reverseEpi (SplitEpi x y) = SplitMono y x
reverseMono :: SplitMono a b -> SplitEpi b a
reverseMono (SplitMono x y) = SplitEpi y x
composeSplitMonoEpi :: SplitMono a b -> SplitEpi b c -> Wedge a c
composeSplitMonoEpi (SplitMono x y) (SplitEpi q w) =
Wedge (q . x) (y . w)
composeSplitEpiMono :: SplitEpi a b -> SplitMono b c -> Wedge a c
composeSplitEpiMono (SplitEpi x y) (SplitMono q w) =
Wedge (q . x) (y . w)
composeSplitEpiPrism :: SplitEpi a b -> Prism' b c -> Format a c
composeSplitEpiPrism (SplitEpi x y) p =
Format ((^? p) . x) (y . review p)
epiAsWedge :: SplitEpi a b -> Wedge a b
epiAsWedge (SplitEpi x y) = Wedge x y
monoAsWedge :: SplitMono a b -> Wedge a b
monoAsWedge (SplitMono x y) = Wedge x y