-- |
-- Convert bijections to and from lens isomorphisms in "Control.Lens.Iso".
{-# LANGUAGE RankNTypes, TypeOperators #-}
module Data.Invertible.Lens
  ( toIso
  , unIso
  ) where

import Data.Invertible.Bijection
import qualified Control.Lens.Iso as L

-- |Convert an isomorphism to a lens.
toIso :: a <-> b -> L.Iso' a b
toIso :: forall a b. (a <-> b) -> Iso' a b
toIso (a -> b
f :<->: b -> a
g) = (a -> b) -> (b -> a) -> Iso a a b b
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
L.iso a -> b
f b -> a
g

-- |Convert a lens to an isomorphism.
unIso :: L.AnIso' a b -> a <-> b
unIso :: forall a b. AnIso' a b -> a <-> b
unIso AnIso' a b
l = AnIso' a b -> ((a -> b) -> (b -> a) -> a <-> b) -> a <-> b
forall s t a b r. AnIso s t a b -> ((s -> a) -> (b -> t) -> r) -> r
L.withIso AnIso' a b
l (a -> b) -> (b -> a) -> a <-> b
forall (a :: * -> * -> *) b c. a b c -> a c b -> Bijection a b c
(:<->:)