11-- | This module defines functions for working with isomorphisms.
22
33module Data.Lens.Iso
4- ( iso , withIso , cloneIso , au , auf , under , curried , uncurried , flipped
4+ ( iso , withIso , cloneIso , re , au , auf , under , curried , uncurried , flipped
55 , module Data.Lens.Types
66 ) where
77
@@ -10,7 +10,7 @@ import Prelude ((<<<), flip, id)
1010import Data.Profunctor (Profunctor , dimap , rmap )
1111import Data.Tuple (Tuple (), curry , uncurry )
1212
13- import Data.Lens.Types (Iso (), IsoP (), AnIso (), AnIsoP (), Exchange (..))
13+ import Data.Lens.Types (Iso (), IsoP (), AnIso (), AnIsoP (), Optic (), Exchange (..), Re (..), runRe )
1414
1515-- | Create an `Iso` from a pair of morphisms.
1616iso :: forall s t a b . (s -> a ) -> (b -> t ) -> Iso s t a b
@@ -25,6 +25,10 @@ withIso l f = case l (Exchange id id) of
2525cloneIso :: forall s t a b . AnIso s t a b -> Iso s t a b
2626cloneIso l = withIso l \x y p -> iso x y p
2727
28+ -- | Reverses an optic.
29+ re :: forall p s t a b . Optic (Re p a b ) s t a b -> Optic p b a t s
30+ re t = runRe (t (Re id))
31+
2832au :: forall s t a b e . AnIso s t a b -> ((b -> t ) -> e -> s ) -> e -> a
2933au l = withIso l \sa bt f e -> sa (f bt e)
3034
0 commit comments