{-# LANGUAGE CPP #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE Trustworthy #-}
{-# OPTIONS_GHC -Wno-redundant-constraints -Wno-trustworthy-safe #-}
module Control.Lens.Review
(
Review
, AReview
, unto
, un
, re
, review, reviews
, reuse, reuses
, (#)
, Bifunctor(bimap)
, retagged
, Reviewable
, reviewing
) where
import Control.Monad.Reader as Reader
import Control.Monad.State as State
import Control.Lens.Getter
import Control.Lens.Internal.Review
import Control.Lens.Type
import Data.Bifunctor
import Data.Functor.Identity
import Data.Profunctor
import Data.Profunctor.Unsafe
import Data.Tagged
import Data.Void
infixr 8 #
unto :: (Profunctor p, Bifunctor p, Functor f) => (b -> t) -> Optic p f s t a b
unto :: forall (p :: * -> * -> *) (f :: * -> *) b t s a.
(Profunctor p, Bifunctor p, Functor f) =>
(b -> t) -> Optic p f s t a b
unto b -> t
f = forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first forall a. Void -> a
absurd forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) a b c.
Profunctor p =>
(a -> b) -> p b c -> p a c
lmap forall a. Void -> a
absurd forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) b c a.
Profunctor p =>
(b -> c) -> p a b -> p a c
rmap (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> t
f)
{-# INLINE unto #-}
un :: (Profunctor p, Bifunctor p, Functor f) => Getting a s a -> Optic' p f a s
un :: forall (p :: * -> * -> *) (f :: * -> *) a s.
(Profunctor p, Bifunctor p, Functor f) =>
Getting a s a -> Optic' p f a s
un = forall (p :: * -> * -> *) (f :: * -> *) b t s a.
(Profunctor p, Bifunctor p, Functor f) =>
(b -> t) -> Optic p f s t a b
unto forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view
re :: AReview t b -> Getter b t
re :: forall t b. AReview t b -> Getter b t
re AReview t b
p = forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
to (forall a. Identity a -> a
runIdentity forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. forall {k} (s :: k) b. Tagged s b -> b
unTagged forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. AReview t b
p forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible b a) =>
p b c -> q a b -> p a c
.# forall {k} (s :: k) b. b -> Tagged s b
Tagged forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible b a) =>
p b c -> q a b -> p a c
.# forall a. a -> Identity a
Identity)
{-# INLINE re #-}
review :: MonadReader b m => AReview t b -> m t
review :: forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review AReview t b
p = forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (forall a. Identity a -> a
runIdentity forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. forall {k} (s :: k) b. Tagged s b -> b
unTagged forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. AReview t b
p forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible b a) =>
p b c -> q a b -> p a c
.# forall {k} (s :: k) b. b -> Tagged s b
Tagged forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible b a) =>
p b c -> q a b -> p a c
.# forall a. a -> Identity a
Identity)
{-# INLINE review #-}
(#) :: AReview t b -> b -> t
# :: forall t b. AReview t b -> b -> t
(#) AReview t b
p = forall a. Identity a -> a
runIdentity forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. forall {k} (s :: k) b. Tagged s b -> b
unTagged forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. AReview t b
p forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible b a) =>
p b c -> q a b -> p a c
.# forall {k} (s :: k) b. b -> Tagged s b
Tagged forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible b a) =>
p b c -> q a b -> p a c
.# forall a. a -> Identity a
Identity
{-# INLINE (#) #-}
reviews :: MonadReader b m => AReview t b -> (t -> r) -> m r
reviews :: forall b (m :: * -> *) t r.
MonadReader b m =>
AReview t b -> (t -> r) -> m r
reviews AReview t b
p t -> r
tr = forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (t -> r
tr forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Identity a -> a
runIdentity forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. forall {k} (s :: k) b. Tagged s b -> b
unTagged forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. AReview t b
p forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible b a) =>
p b c -> q a b -> p a c
.# forall {k} (s :: k) b. b -> Tagged s b
Tagged forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible b a) =>
p b c -> q a b -> p a c
.# forall a. a -> Identity a
Identity)
{-# INLINE reviews #-}
reuse :: MonadState b m => AReview t b -> m t
reuse :: forall b (m :: * -> *) t. MonadState b m => AReview t b -> m t
reuse AReview t b
p = forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (forall a. Identity a -> a
runIdentity forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. forall {k} (s :: k) b. Tagged s b -> b
unTagged forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. AReview t b
p forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible b a) =>
p b c -> q a b -> p a c
.# forall {k} (s :: k) b. b -> Tagged s b
Tagged forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible b a) =>
p b c -> q a b -> p a c
.# forall a. a -> Identity a
Identity)
{-# INLINE reuse #-}
reuses :: MonadState b m => AReview t b -> (t -> r) -> m r
reuses :: forall b (m :: * -> *) t r.
MonadState b m =>
AReview t b -> (t -> r) -> m r
reuses AReview t b
p t -> r
tr = forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (t -> r
tr forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Identity a -> a
runIdentity forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. forall {k} (s :: k) b. Tagged s b -> b
unTagged forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. AReview t b
p forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible b a) =>
p b c -> q a b -> p a c
.# forall {k} (s :: k) b. b -> Tagged s b
Tagged forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible b a) =>
p b c -> q a b -> p a c
.# forall a. a -> Identity a
Identity)
{-# INLINE reuses #-}
reviewing :: (Bifunctor p, Functor f) => Optic Tagged Identity s t a b -> Optic' p f t b
reviewing :: forall (p :: * -> * -> *) (f :: * -> *) s t a b.
(Bifunctor p, Functor f) =>
Optic Tagged Identity s t a b -> Optic' p f t b
reviewing Optic Tagged Identity s t a b
p = forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap b -> t
f (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> t
f) where
f :: b -> t
f = forall a. Identity a -> a
runIdentity forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (s :: k) b. Tagged s b -> b
unTagged forall b c a. (b -> c) -> (a -> b) -> a -> c
. Optic Tagged Identity s t a b
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (s :: k) b. b -> Tagged s b
Tagged forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Identity a
Identity