{-# LANGUAGE CPP #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE TypeInType #-}
#include "lens-common.h"
module Control.Lens.Iso
(
Iso, Iso'
, AnIso, AnIso'
, iso
, from
, cloneIso
, withIso
, au
, auf
, xplat
, xplatf
, under
, mapping
, simple
, non, non'
, anon
, enum
, curried, uncurried
, flipped
, swapped
, pattern Swapped
, strict, lazy
, pattern Strict
, pattern Lazy
, Reversing(..)
, reversed
, pattern Reversed
, involuted
, pattern List
, magma
, imagma
, Magma
, contramapping
, Profunctor(dimap,rmap,lmap)
, dimapping
, lmapping
, rmapping
, bimapping
, firsting
, seconding
, coerced
) where
import Control.Lens.Equality (simple)
import Control.Lens.Getter
import Control.Lens.Fold
import Control.Lens.Internal.Context
import Control.Lens.Internal.Indexed
import Control.Lens.Internal.Iso as Iso
import Control.Lens.Internal.Magma
import Control.Lens.Prism
import Control.Lens.Review
import Control.Lens.Type
import Data.Bifunctor
import Data.Bifunctor.Swap (Swap (..))
import Data.Functor.Identity
import Data.Strict.Classes (Strict (..))
import Data.Maybe
import Data.Profunctor
import Data.Profunctor.Unsafe
import Data.Coerce
import qualified GHC.Exts as Exts
import GHC.Exts (TYPE)
type AnIso s t a b = Exchange a b a (Identity b) -> Exchange a b s (Identity t)
type AnIso' s a = AnIso s s a a
iso :: (s -> a) -> (b -> t) -> Iso s t a b
iso :: (s -> a) -> (b -> t) -> Iso s t a b
iso s -> a
sa b -> t
bt = (s -> a) -> (f b -> f t) -> p a (f b) -> p s (f t)
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap s -> a
sa ((b -> t) -> f b -> f t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> t
bt)
{-# INLINE iso #-}
from :: AnIso s t a b -> Iso b a t s
from :: AnIso s t a b -> Iso b a t s
from AnIso s t a b
l = AnIso s t a b
-> ((s -> a) -> (b -> t) -> p t (f s) -> p b (f a))
-> p t (f s)
-> p b (f a)
forall s t a b r. AnIso s t a b -> ((s -> a) -> (b -> t) -> r) -> r
withIso AnIso s t a b
l (((s -> a) -> (b -> t) -> p t (f s) -> p b (f a))
-> p t (f s) -> p b (f a))
-> ((s -> a) -> (b -> t) -> p t (f s) -> p b (f a))
-> p t (f s)
-> p b (f a)
forall a b. (a -> b) -> a -> b
$ \s -> a
sa b -> t
bt -> (b -> t) -> (s -> a) -> Iso b a t s
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso b -> t
bt s -> a
sa
{-# INLINE from #-}
withIso :: forall s t a b rep (r :: TYPE rep).
AnIso s t a b -> ((s -> a) -> (b -> t) -> r) -> r
withIso :: AnIso s t a b -> ((s -> a) -> (b -> t) -> r) -> r
withIso AnIso s t a b
ai (s -> a) -> (b -> t) -> r
k = case AnIso s t a b
ai ((a -> a) -> (b -> Identity b) -> Exchange a b a (Identity b)
forall a b s t. (s -> a) -> (b -> t) -> Exchange a b s t
Exchange a -> a
forall a. a -> a
id b -> Identity b
forall a. a -> Identity a
Identity) of
Exchange s -> a
sa b -> Identity t
bt -> (s -> a) -> (b -> t) -> r
k s -> a
sa (Identity t -> t
forall a. Identity a -> a
runIdentity (Identity t -> t) -> (b -> Identity t) -> b -> t
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. b -> Identity t
bt)
{-# INLINE withIso #-}
cloneIso :: AnIso s t a b -> Iso s t a b
cloneIso :: AnIso s t a b -> Iso s t a b
cloneIso AnIso s t a b
k = AnIso s t a b
-> ((s -> a) -> (b -> t) -> p a (f b) -> p s (f t))
-> p a (f b)
-> p s (f t)
forall s t a b r. AnIso s t a b -> ((s -> a) -> (b -> t) -> r) -> r
withIso AnIso s t a b
k (((s -> a) -> (b -> t) -> p a (f b) -> p s (f t))
-> p a (f b) -> p s (f t))
-> ((s -> a) -> (b -> t) -> p a (f b) -> p s (f t))
-> p a (f b)
-> p s (f t)
forall a b. (a -> b) -> a -> b
$ \s -> a
sa b -> t
bt -> (s -> a) -> (b -> t) -> Iso s t a b
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso s -> a
sa b -> t
bt
{-# INLINE cloneIso #-}
au :: Functor f => AnIso s t a b -> ((b -> t) -> f s) -> f a
au :: AnIso s t a b -> ((b -> t) -> f s) -> f a
au AnIso s t a b
k = AnIso s t a b
-> ((s -> a) -> (b -> t) -> ((b -> t) -> f s) -> f a)
-> ((b -> t) -> f s)
-> f a
forall s t a b r. AnIso s t a b -> ((s -> a) -> (b -> t) -> r) -> r
withIso AnIso s t a b
k (((s -> a) -> (b -> t) -> ((b -> t) -> f s) -> f a)
-> ((b -> t) -> f s) -> f a)
-> ((s -> a) -> (b -> t) -> ((b -> t) -> f s) -> f a)
-> ((b -> t) -> f s)
-> f a
forall a b. (a -> b) -> a -> b
$ \ s -> a
sa b -> t
bt (b -> t) -> f s
f -> (s -> a) -> f s -> f a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap s -> a
sa ((b -> t) -> f s
f b -> t
bt)
{-# INLINE au #-}
auf :: (Functor f, Functor g) => AnIso s t a b -> (f t -> g s) -> f b -> g a
auf :: AnIso s t a b -> (f t -> g s) -> f b -> g a
auf AnIso s t a b
k f t -> g s
ftgs f b
fb = AnIso s t a b -> ((s -> a) -> (b -> t) -> g a) -> g a
forall s t a b r. AnIso s t a b -> ((s -> a) -> (b -> t) -> r) -> r
withIso AnIso s t a b
k (((s -> a) -> (b -> t) -> g a) -> g a)
-> ((s -> a) -> (b -> t) -> g a) -> g a
forall a b. (a -> b) -> a -> b
$ \s -> a
sa b -> t
bt -> s -> a
sa (s -> a) -> g s -> g a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f t -> g s
ftgs (b -> t
bt (b -> t) -> f b -> f t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f b
fb)
{-# INLINE auf #-}
xplat :: Optic (Costar ((->) s)) g s t a b -> ((s -> a) -> g b) -> g t
xplat :: Optic (Costar ((->) s)) g s t a b -> ((s -> a) -> g b) -> g t
xplat Optic (Costar ((->) s)) g s t a b
f (s -> a) -> g b
g = Optic (Costar ((->) s)) g s t a b
-> ((s -> a) -> g b) -> (s -> s) -> g t
forall k k (f :: k -> *) (g :: k -> *) (s :: k) (t :: k) (a :: k)
(b :: k).
Optic (Costar f) g s t a b -> (f a -> g b) -> f s -> g t
xplatf Optic (Costar ((->) s)) g s t a b
f (s -> a) -> g b
g s -> s
forall a. a -> a
id
xplatf :: Optic (Costar f) g s t a b -> (f a -> g b) -> f s -> g t
xplatf :: Optic (Costar f) g s t a b -> (f a -> g b) -> f s -> g t
xplatf = Optic (Costar f) g s t a b -> (f a -> g b) -> f s -> g t
coerce
{-# INLINE xplat #-}
under :: AnIso s t a b -> (t -> s) -> b -> a
under :: AnIso s t a b -> (t -> s) -> b -> a
under AnIso s t a b
k = AnIso s t a b
-> ((s -> a) -> (b -> t) -> (t -> s) -> b -> a)
-> (t -> s)
-> b
-> a
forall s t a b r. AnIso s t a b -> ((s -> a) -> (b -> t) -> r) -> r
withIso AnIso s t a b
k (((s -> a) -> (b -> t) -> (t -> s) -> b -> a)
-> (t -> s) -> b -> a)
-> ((s -> a) -> (b -> t) -> (t -> s) -> b -> a)
-> (t -> s)
-> b
-> a
forall a b. (a -> b) -> a -> b
$ \ s -> a
sa b -> t
bt t -> s
ts -> s -> a
sa (s -> a) -> (b -> s) -> b -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t -> s
ts (t -> s) -> (b -> t) -> b -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> t
bt
{-# INLINE under #-}
enum :: Enum a => Iso' Int a
enum :: Iso' Int a
enum = (Int -> a) -> (a -> Int) -> Iso' Int a
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso Int -> a
forall a. Enum a => Int -> a
toEnum a -> Int
forall a. Enum a => a -> Int
fromEnum
{-# INLINE enum #-}
mapping :: (Functor f, Functor g) => AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
mapping :: AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
mapping AnIso s t a b
k = AnIso s t a b
-> ((s -> a) -> (b -> t) -> p (f a) (f (g b)) -> p (f s) (f (g t)))
-> p (f a) (f (g b))
-> p (f s) (f (g t))
forall s t a b r. AnIso s t a b -> ((s -> a) -> (b -> t) -> r) -> r
withIso AnIso s t a b
k (((s -> a) -> (b -> t) -> p (f a) (f (g b)) -> p (f s) (f (g t)))
-> p (f a) (f (g b)) -> p (f s) (f (g t)))
-> ((s -> a) -> (b -> t) -> p (f a) (f (g b)) -> p (f s) (f (g t)))
-> p (f a) (f (g b))
-> p (f s) (f (g t))
forall a b. (a -> b) -> a -> b
$ \ s -> a
sa b -> t
bt -> (f s -> f a) -> (g b -> g t) -> Iso (f s) (g t) (f a) (g b)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso ((s -> a) -> f s -> f a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap s -> a
sa) ((b -> t) -> g b -> g t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> t
bt)
{-# INLINE mapping #-}
non :: Eq a => a -> Iso' (Maybe a) a
non :: a -> Iso' (Maybe a) a
non a
a = APrism' a () -> Iso' (Maybe a) a
forall a. APrism' a () -> Iso' (Maybe a) a
non' (APrism' a () -> Iso' (Maybe a) a)
-> APrism' a () -> Iso' (Maybe a) a
forall a b. (a -> b) -> a -> b
$ a -> Prism' a ()
forall a. Eq a => a -> Prism' a ()
only a
a
{-# INLINE non #-}
non' :: APrism' a () -> Iso' (Maybe a) a
non' :: APrism' a () -> Iso' (Maybe a) a
non' APrism' a ()
p = (Maybe a -> a) -> (a -> Maybe a) -> Iso' (Maybe a) a
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (a -> Maybe a -> a
forall a. a -> Maybe a -> a
fromMaybe a
def) a -> Maybe a
go where
def :: a
def = AReview a () -> () -> a
forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review (APrism' a () -> Prism a a () ()
forall s t a b. APrism s t a b -> Prism s t a b
clonePrism APrism' a ()
p) ()
go :: a -> Maybe a
go a
b | Getting Any a () -> a -> Bool
forall s a. Getting Any s a -> s -> Bool
has (APrism' a () -> Prism a a () ()
forall s t a b. APrism s t a b -> Prism s t a b
clonePrism APrism' a ()
p) a
b = Maybe a
forall a. Maybe a
Nothing
| Bool
otherwise = a -> Maybe a
forall a. a -> Maybe a
Just a
b
{-# INLINE non' #-}
anon :: a -> (a -> Bool) -> Iso' (Maybe a) a
anon :: a -> (a -> Bool) -> Iso' (Maybe a) a
anon a
a a -> Bool
p = (Maybe a -> a) -> (a -> Maybe a) -> Iso' (Maybe a) a
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (a -> Maybe a -> a
forall a. a -> Maybe a -> a
fromMaybe a
a) a -> Maybe a
go where
go :: a -> Maybe a
go a
b | a -> Bool
p a
b = Maybe a
forall a. Maybe a
Nothing
| Bool
otherwise = a -> Maybe a
forall a. a -> Maybe a
Just a
b
{-# INLINE anon #-}
curried :: Iso ((a,b) -> c) ((d,e) -> f) (a -> b -> c) (d -> e -> f)
curried :: p (a -> b -> c) (f (d -> e -> f))
-> p ((a, b) -> c) (f ((d, e) -> f))
curried = (((a, b) -> c) -> a -> b -> c)
-> ((d -> e -> f) -> (d, e) -> f)
-> Iso ((a, b) -> c) ((d, e) -> f) (a -> b -> c) (d -> e -> f)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso ((a, b) -> c) -> a -> b -> c
forall a b c. ((a, b) -> c) -> a -> b -> c
curry (d -> e -> f) -> (d, e) -> f
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry
{-# INLINE curried #-}
uncurried :: Iso (a -> b -> c) (d -> e -> f) ((a,b) -> c) ((d,e) -> f)
uncurried :: p ((a, b) -> c) (f ((d, e) -> f))
-> p (a -> b -> c) (f (d -> e -> f))
uncurried = ((a -> b -> c) -> (a, b) -> c)
-> (((d, e) -> f) -> d -> e -> f)
-> Iso (a -> b -> c) (d -> e -> f) ((a, b) -> c) ((d, e) -> f)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (a -> b -> c) -> (a, b) -> c
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ((d, e) -> f) -> d -> e -> f
forall a b c. ((a, b) -> c) -> a -> b -> c
curry
{-# INLINE uncurried #-}
flipped :: Iso (a -> b -> c) (a' -> b' -> c') (b -> a -> c) (b' -> a' -> c')
flipped :: p (b -> a -> c) (f (b' -> a' -> c'))
-> p (a -> b -> c) (f (a' -> b' -> c'))
flipped = ((a -> b -> c) -> b -> a -> c)
-> ((b' -> a' -> c') -> a' -> b' -> c')
-> Iso
(a -> b -> c) (a' -> b' -> c') (b -> a -> c) (b' -> a' -> c')
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (a -> b -> c) -> b -> a -> c
forall a b c. (a -> b -> c) -> b -> a -> c
flip (b' -> a' -> c') -> a' -> b' -> c'
forall a b c. (a -> b -> c) -> b -> a -> c
flip
{-# INLINE flipped #-}
swapped :: Swap p => Iso (p a b) (p c d) (p b a) (p d c)
swapped :: Iso (p a b) (p c d) (p b a) (p d c)
swapped = (p a b -> p b a)
-> (p d c -> p c d) -> Iso (p a b) (p c d) (p b a) (p d c)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso p a b -> p b a
forall (p :: * -> * -> *) a b. Swap p => p a b -> p b a
swap p d c -> p c d
forall (p :: * -> * -> *) a b. Swap p => p a b -> p b a
swap
{-# INLINE swapped #-}
strict :: Strict lazy strict => Iso' lazy strict
strict :: Iso' lazy strict
strict = (lazy -> strict) -> (strict -> lazy) -> Iso' lazy strict
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso lazy -> strict
forall lazy strict. Strict lazy strict => lazy -> strict
toStrict strict -> lazy
forall lazy strict. Strict lazy strict => strict -> lazy
toLazy
{-# INLINE strict #-}
pattern Strict :: Strict s t => t -> s
pattern $bStrict :: t -> s
$mStrict :: forall r s t. Strict s t => s -> (t -> r) -> (Void# -> r) -> r
Strict a <- (view strict -> a) where
Strict t
a = AReview s t -> t -> s
forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review AReview s t
forall lazy strict. Strict lazy strict => Iso' lazy strict
strict t
a
pattern Lazy :: Strict t s => t -> s
pattern $bLazy :: t -> s
$mLazy :: forall r t s. Strict t s => s -> (t -> r) -> (Void# -> r) -> r
Lazy a <- (view lazy -> a) where
Lazy t
a = AReview s t -> t -> s
forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review AReview s t
forall lazy strict. Strict lazy strict => Iso' strict lazy
lazy t
a
pattern Swapped :: Swap p => p b a -> p a b
pattern $bSwapped :: p b a -> p a b
$mSwapped :: forall r (p :: * -> * -> *) b a.
Swap p =>
p a b -> (p b a -> r) -> (Void# -> r) -> r
Swapped a <- (view swapped -> a) where
Swapped p b a
a = AReview (p a b) (p b a) -> p b a -> p a b
forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review AReview (p a b) (p b a)
forall (p :: * -> * -> *) a b c d.
Swap p =>
Iso (p a b) (p c d) (p b a) (p d c)
swapped p b a
a
pattern Reversed :: Reversing t => t -> t
pattern $bReversed :: t -> t
$mReversed :: forall r t. Reversing t => t -> (t -> r) -> (Void# -> r) -> r
Reversed a <- (view reversed -> a) where
Reversed t
a = AReview t t -> t -> t
forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review AReview t t
forall a. Reversing a => Iso' a a
reversed t
a
lazy :: Strict lazy strict => Iso' strict lazy
lazy :: Iso' strict lazy
lazy = (strict -> lazy) -> (lazy -> strict) -> Iso' strict lazy
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso strict -> lazy
forall lazy strict. Strict lazy strict => strict -> lazy
toLazy lazy -> strict
forall lazy strict. Strict lazy strict => lazy -> strict
toStrict
{-# INLINE lazy #-}
reversed :: Reversing a => Iso' a a
reversed :: Iso' a a
reversed = (a -> a) -> Iso' a a
forall a. (a -> a) -> Iso' a a
involuted a -> a
forall t. Reversing t => t -> t
Iso.reversing
involuted :: (a -> a) -> Iso' a a
involuted :: (a -> a) -> Iso' a a
involuted a -> a
a = (a -> a) -> (a -> a) -> Iso' a a
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso a -> a
a a -> a
a
{-# INLINE involuted #-}
pattern List :: Exts.IsList l => [Exts.Item l] -> l
pattern $bList :: [Item l] -> l
$mList :: forall r l. IsList l => l -> ([Item l] -> r) -> (Void# -> r) -> r
List a <- (Exts.toList -> a) where
List [Item l]
a = [Item l] -> l
forall l. IsList l => [Item l] -> l
Exts.fromList [Item l]
a
magma :: LensLike (Mafic a b) s t a b -> Iso s u (Magma Int t b a) (Magma j u c c)
magma :: LensLike (Mafic a b) s t a b
-> Iso s u (Magma Int t b a) (Magma j u c c)
magma LensLike (Mafic a b) s t a b
l = (s -> Magma Int t b a)
-> (Magma j u c c -> u)
-> Iso s u (Magma Int t b a) (Magma j u c c)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (Mafic a b t -> Magma Int t b a
forall a b t. Mafic a b t -> Magma Int t b a
runMafic (Mafic a b t -> Magma Int t b a)
-> (s -> Mafic a b t) -> s -> Magma Int t b a
forall (p :: * -> * -> *) b c a.
Profunctor p =>
(b -> c) -> p a b -> p a c
`rmap` LensLike (Mafic a b) s t a b
l a -> Mafic a b b
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell) Magma j u c c -> u
forall i t a. Magma i t a a -> t
runMagma
{-# INLINE magma #-}
imagma :: Over (Indexed i) (Molten i a b) s t a b -> Iso s t' (Magma i t b a) (Magma j t' c c)
imagma :: Over (Indexed i) (Molten i a b) s t a b
-> Iso s t' (Magma i t b a) (Magma j t' c c)
imagma Over (Indexed i) (Molten i a b) s t a b
l = (s -> Magma i t b a)
-> (Magma j t' c c -> t')
-> Iso s t' (Magma i t b a) (Magma j t' c c)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (Molten i a b t -> Magma i t b a
forall i a b t. Molten i a b t -> Magma i t b a
runMolten (Molten i a b t -> Magma i t b a)
-> (s -> Molten i a b t) -> s -> Magma i t b a
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. Over (Indexed i) (Molten i a b) s t a b
l Indexed i a (Molten i a b b)
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell) (Molten j c c t' -> t'
forall (w :: * -> * -> * -> *) a t.
IndexedComonad w =>
w a a t -> t
iextract (Molten j c c t' -> t')
-> (Magma j t' c c -> Molten j c c t') -> Magma j t' c c -> t'
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible b a) =>
p b c -> q a b -> p a c
.# Magma j t' c c -> Molten j c c t'
forall i a b t. Magma i t b a -> Molten i a b t
Molten)
{-# INLINE imagma #-}
contramapping :: Contravariant f => AnIso s t a b -> Iso (f a) (f b) (f s) (f t)
contramapping :: AnIso s t a b -> Iso (f a) (f b) (f s) (f t)
contramapping AnIso s t a b
f = AnIso s t a b
-> ((s -> a) -> (b -> t) -> p (f s) (f (f t)) -> p (f a) (f (f b)))
-> p (f s) (f (f t))
-> p (f a) (f (f b))
forall s t a b r. AnIso s t a b -> ((s -> a) -> (b -> t) -> r) -> r
withIso AnIso s t a b
f (((s -> a) -> (b -> t) -> p (f s) (f (f t)) -> p (f a) (f (f b)))
-> p (f s) (f (f t)) -> p (f a) (f (f b)))
-> ((s -> a) -> (b -> t) -> p (f s) (f (f t)) -> p (f a) (f (f b)))
-> p (f s) (f (f t))
-> p (f a) (f (f b))
forall a b. (a -> b) -> a -> b
$ \ s -> a
sa b -> t
bt -> (f a -> f s) -> (f t -> f b) -> Iso (f a) (f b) (f s) (f t)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso ((s -> a) -> f a -> f s
forall (f :: * -> *) a b. Contravariant f => (a -> b) -> f b -> f a
contramap s -> a
sa) ((b -> t) -> f t -> f b
forall (f :: * -> *) a b. Contravariant f => (a -> b) -> f b -> f a
contramap b -> t
bt)
{-# INLINE contramapping #-}
dimapping :: (Profunctor p, Profunctor q) => AnIso s t a b -> AnIso s' t' a' b' -> Iso (p a s') (q b t') (p s a') (q t b')
dimapping :: AnIso s t a b
-> AnIso s' t' a' b' -> Iso (p a s') (q b t') (p s a') (q t b')
dimapping AnIso s t a b
f AnIso s' t' a' b'
g = AnIso s t a b
-> ((s -> a)
-> (b -> t) -> p (p s a') (f (q t b')) -> p (p a s') (f (q b t')))
-> p (p s a') (f (q t b'))
-> p (p a s') (f (q b t'))
forall s t a b r. AnIso s t a b -> ((s -> a) -> (b -> t) -> r) -> r
withIso AnIso s t a b
f (((s -> a)
-> (b -> t) -> p (p s a') (f (q t b')) -> p (p a s') (f (q b t')))
-> p (p s a') (f (q t b')) -> p (p a s') (f (q b t')))
-> ((s -> a)
-> (b -> t) -> p (p s a') (f (q t b')) -> p (p a s') (f (q b t')))
-> p (p s a') (f (q t b'))
-> p (p a s') (f (q b t'))
forall a b. (a -> b) -> a -> b
$ \ s -> a
sa b -> t
bt -> AnIso s' t' a' b'
-> ((s' -> a')
-> (b' -> t')
-> p (p s a') (f (q t b'))
-> p (p a s') (f (q b t')))
-> p (p s a') (f (q t b'))
-> p (p a s') (f (q b t'))
forall s t a b r. AnIso s t a b -> ((s -> a) -> (b -> t) -> r) -> r
withIso AnIso s' t' a' b'
g (((s' -> a')
-> (b' -> t')
-> p (p s a') (f (q t b'))
-> p (p a s') (f (q b t')))
-> p (p s a') (f (q t b')) -> p (p a s') (f (q b t')))
-> ((s' -> a')
-> (b' -> t')
-> p (p s a') (f (q t b'))
-> p (p a s') (f (q b t')))
-> p (p s a') (f (q t b'))
-> p (p a s') (f (q b t'))
forall a b. (a -> b) -> a -> b
$ \ s' -> a'
s'a' b' -> t'
b't' ->
(p a s' -> p s a')
-> (q t b' -> q b t') -> Iso (p a s') (q b t') (p s a') (q t b')
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso ((s -> a) -> (s' -> a') -> p a s' -> p s a'
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap s -> a
sa s' -> a'
s'a') ((b -> t) -> (b' -> t') -> q t b' -> q b t'
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap b -> t
bt b' -> t'
b't')
{-# INLINE dimapping #-}
lmapping :: (Profunctor p, Profunctor q) => AnIso s t a b -> Iso (p a x) (q b y) (p s x) (q t y)
lmapping :: AnIso s t a b -> Iso (p a x) (q b y) (p s x) (q t y)
lmapping AnIso s t a b
f = AnIso s t a b
-> ((s -> a)
-> (b -> t) -> p (p s x) (f (q t y)) -> p (p a x) (f (q b y)))
-> p (p s x) (f (q t y))
-> p (p a x) (f (q b y))
forall s t a b r. AnIso s t a b -> ((s -> a) -> (b -> t) -> r) -> r
withIso AnIso s t a b
f (((s -> a)
-> (b -> t) -> p (p s x) (f (q t y)) -> p (p a x) (f (q b y)))
-> p (p s x) (f (q t y)) -> p (p a x) (f (q b y)))
-> ((s -> a)
-> (b -> t) -> p (p s x) (f (q t y)) -> p (p a x) (f (q b y)))
-> p (p s x) (f (q t y))
-> p (p a x) (f (q b y))
forall a b. (a -> b) -> a -> b
$ \ s -> a
sa b -> t
bt -> (p a x -> p s x)
-> (q t y -> q b y) -> Iso (p a x) (q b y) (p s x) (q t y)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso ((s -> a) -> p a x -> p s x
forall (p :: * -> * -> *) a b c.
Profunctor p =>
(a -> b) -> p b c -> p a c
lmap s -> a
sa) ((b -> t) -> q t y -> q b y
forall (p :: * -> * -> *) a b c.
Profunctor p =>
(a -> b) -> p b c -> p a c
lmap b -> t
bt)
{-# INLINE lmapping #-}
rmapping :: (Profunctor p, Profunctor q) => AnIso s t a b -> Iso (p x s) (q y t) (p x a) (q y b)
rmapping :: AnIso s t a b -> Iso (p x s) (q y t) (p x a) (q y b)
rmapping AnIso s t a b
g = AnIso s t a b
-> ((s -> a)
-> (b -> t) -> p (p x a) (f (q y b)) -> p (p x s) (f (q y t)))
-> p (p x a) (f (q y b))
-> p (p x s) (f (q y t))
forall s t a b r. AnIso s t a b -> ((s -> a) -> (b -> t) -> r) -> r
withIso AnIso s t a b
g (((s -> a)
-> (b -> t) -> p (p x a) (f (q y b)) -> p (p x s) (f (q y t)))
-> p (p x a) (f (q y b)) -> p (p x s) (f (q y t)))
-> ((s -> a)
-> (b -> t) -> p (p x a) (f (q y b)) -> p (p x s) (f (q y t)))
-> p (p x a) (f (q y b))
-> p (p x s) (f (q y t))
forall a b. (a -> b) -> a -> b
$ \ s -> a
sa b -> t
bt -> (p x s -> p x a)
-> (q y b -> q y t) -> Iso (p x s) (q y t) (p x a) (q y b)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso ((s -> a) -> p x s -> p x a
forall (p :: * -> * -> *) b c a.
Profunctor p =>
(b -> c) -> p a b -> p a c
rmap s -> a
sa) ((b -> t) -> q y b -> q y t
forall (p :: * -> * -> *) b c a.
Profunctor p =>
(b -> c) -> p a b -> p a c
rmap b -> t
bt)
{-# INLINE rmapping #-}
bimapping :: (Bifunctor f, Bifunctor g) => AnIso s t a b -> AnIso s' t' a' b' -> Iso (f s s') (g t t') (f a a') (g b b')
bimapping :: AnIso s t a b
-> AnIso s' t' a' b' -> Iso (f s s') (g t t') (f a a') (g b b')
bimapping AnIso s t a b
f AnIso s' t' a' b'
g = AnIso s t a b
-> ((s -> a)
-> (b -> t) -> p (f a a') (f (g b b')) -> p (f s s') (f (g t t')))
-> p (f a a') (f (g b b'))
-> p (f s s') (f (g t t'))
forall s t a b r. AnIso s t a b -> ((s -> a) -> (b -> t) -> r) -> r
withIso AnIso s t a b
f (((s -> a)
-> (b -> t) -> p (f a a') (f (g b b')) -> p (f s s') (f (g t t')))
-> p (f a a') (f (g b b')) -> p (f s s') (f (g t t')))
-> ((s -> a)
-> (b -> t) -> p (f a a') (f (g b b')) -> p (f s s') (f (g t t')))
-> p (f a a') (f (g b b'))
-> p (f s s') (f (g t t'))
forall a b. (a -> b) -> a -> b
$ \ s -> a
sa b -> t
bt -> AnIso s' t' a' b'
-> ((s' -> a')
-> (b' -> t')
-> p (f a a') (f (g b b'))
-> p (f s s') (f (g t t')))
-> p (f a a') (f (g b b'))
-> p (f s s') (f (g t t'))
forall s t a b r. AnIso s t a b -> ((s -> a) -> (b -> t) -> r) -> r
withIso AnIso s' t' a' b'
g (((s' -> a')
-> (b' -> t')
-> p (f a a') (f (g b b'))
-> p (f s s') (f (g t t')))
-> p (f a a') (f (g b b')) -> p (f s s') (f (g t t')))
-> ((s' -> a')
-> (b' -> t')
-> p (f a a') (f (g b b'))
-> p (f s s') (f (g t t')))
-> p (f a a') (f (g b b'))
-> p (f s s') (f (g t t'))
forall a b. (a -> b) -> a -> b
$ \s' -> a'
s'a' b' -> t'
b't' ->
(f s s' -> f a a')
-> (g b b' -> g t t') -> Iso (f s s') (g t t') (f a a') (g b b')
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso ((s -> a) -> (s' -> a') -> f s s' -> f a a'
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap s -> a
sa s' -> a'
s'a') ((b -> t) -> (b' -> t') -> g b b' -> g t t'
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap b -> t
bt b' -> t'
b't')
{-# INLINE bimapping #-}
firsting :: (Bifunctor f, Bifunctor g) => AnIso s t a b -> Iso (f s x) (g t y) (f a x) (g b y)
firsting :: AnIso s t a b -> Iso (f s x) (g t y) (f a x) (g b y)
firsting AnIso s t a b
p = AnIso s t a b
-> ((s -> a)
-> (b -> t) -> p (f a x) (f (g b y)) -> p (f s x) (f (g t y)))
-> p (f a x) (f (g b y))
-> p (f s x) (f (g t y))
forall s t a b r. AnIso s t a b -> ((s -> a) -> (b -> t) -> r) -> r
withIso AnIso s t a b
p (((s -> a)
-> (b -> t) -> p (f a x) (f (g b y)) -> p (f s x) (f (g t y)))
-> p (f a x) (f (g b y)) -> p (f s x) (f (g t y)))
-> ((s -> a)
-> (b -> t) -> p (f a x) (f (g b y)) -> p (f s x) (f (g t y)))
-> p (f a x) (f (g b y))
-> p (f s x) (f (g t y))
forall a b. (a -> b) -> a -> b
$ \ s -> a
sa b -> t
bt -> (f s x -> f a x)
-> (g b y -> g t y) -> Iso (f s x) (g t y) (f a x) (g b y)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso ((s -> a) -> f s x -> f a x
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first s -> a
sa) ((b -> t) -> g b y -> g t y
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first b -> t
bt)
{-# INLINE firsting #-}
seconding :: (Bifunctor f, Bifunctor g) => AnIso s t a b -> Iso (f x s) (g y t) (f x a) (g y b)
seconding :: AnIso s t a b -> Iso (f x s) (g y t) (f x a) (g y b)
seconding AnIso s t a b
p = AnIso s t a b
-> ((s -> a)
-> (b -> t) -> p (f x a) (f (g y b)) -> p (f x s) (f (g y t)))
-> p (f x a) (f (g y b))
-> p (f x s) (f (g y t))
forall s t a b r. AnIso s t a b -> ((s -> a) -> (b -> t) -> r) -> r
withIso AnIso s t a b
p (((s -> a)
-> (b -> t) -> p (f x a) (f (g y b)) -> p (f x s) (f (g y t)))
-> p (f x a) (f (g y b)) -> p (f x s) (f (g y t)))
-> ((s -> a)
-> (b -> t) -> p (f x a) (f (g y b)) -> p (f x s) (f (g y t)))
-> p (f x a) (f (g y b))
-> p (f x s) (f (g y t))
forall a b. (a -> b) -> a -> b
$ \ s -> a
sa b -> t
bt -> (f x s -> f x a)
-> (g y b -> g y t) -> Iso (f x s) (g y t) (f x a) (g y b)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso ((s -> a) -> f x s -> f x a
forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second s -> a
sa) ((b -> t) -> g y b -> g y t
forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second b -> t
bt)
{-# INLINE seconding #-}
coerced :: forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
coerced :: Iso s t a b
coerced p a (f b)
l = (f b -> f t) -> p a (f b) -> p a (f t)
forall (p :: * -> * -> *) b c a.
Profunctor p =>
(b -> c) -> p a b -> p a c
rmap ((b -> t) -> f b -> f t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> t
coerce) p a (f b)
l p a (f t) -> (s -> a) -> p s (f t)
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible b a) =>
p b c -> q a b -> p a c
.# s -> a
coerce
{-# INLINE coerced #-}