module Optics.Lens
(
Lens
, Lens'
, lens
, equality'
, alongside
, united
, withLens
, A_Lens
, LensVL
, LensVL'
, lensVL
, toLensVL
, withLensVL
)
where
import Data.Profunctor.Indexed
import Optics.Internal.Optic
type Lens s t a b = Optic A_Lens NoIx s t a b
type Lens' s a = Optic' A_Lens NoIx s a
type LensVL s t a b = forall f. Functor f => (a -> f b) -> s -> f t
type LensVL' s a = LensVL s s a a
lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b
lens :: forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens s -> a
get s -> b -> t
set = forall k (is :: IxList) s t a b.
(forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ k p i (Curry is i) s t a b)
-> Optic k is s t a b
Optic forall a b. (a -> b) -> a -> b
$
forall (p :: * -> * -> * -> *) a b c d i.
Profunctor p =>
(a -> b) -> (c -> d) -> p i b c -> p i a d
dimap (\s
s -> (s -> a
get s
s, s
s))
(\(b
b, s
s) -> s -> b -> t
set s
s b
b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> * -> *) i a b c.
Strong p =>
p i a b -> p i (a, c) (b, c)
first'
{-# INLINE lens #-}
withLens
:: Is k A_Lens
=> Optic k is s t a b
-> ((s -> a) -> (s -> b -> t) -> r)
-> r
withLens :: forall k (is :: IxList) s t a b r.
Is k A_Lens =>
Optic k is s t a b -> ((s -> a) -> (s -> b -> t) -> r) -> r
withLens Optic k is s t a b
o (s -> a) -> (s -> b -> t) -> r
k = case forall (p :: * -> * -> * -> *) k (is :: IxList) s t a b i.
Profunctor p =>
Optic k is s t a b -> Optic_ k p i (Curry is i) s t a b
getOptic (forall destKind srcKind (is :: IxList) s t a b.
Is srcKind destKind =>
Optic srcKind is s t a b -> Optic destKind is s t a b
castOptic @A_Lens Optic k is s t a b
o) forall a b. (a -> b) -> a -> b
$ forall a b i s t. (s -> a) -> (s -> b -> t) -> Store a b i s t
Store forall a. a -> a
id (\a
_ -> forall a. a -> a
id) of
Store s -> a
get s -> b -> t
set -> (s -> a) -> (s -> b -> t) -> r
k s -> a
get s -> b -> t
set
{-# INLINE withLens #-}
lensVL :: LensVL s t a b -> Lens s t a b
lensVL :: forall s t a b. LensVL s t a b -> Lens s t a b
lensVL LensVL s t a b
l = forall k (is :: IxList) s t a b.
(forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ k p i (Curry is i) s t a b)
-> Optic k is s t a b
Optic (forall (p :: * -> * -> * -> *) a b s t i.
Strong p =>
(forall (f :: * -> *). Functor f => (a -> f b) -> s -> f t)
-> p i a b -> p i s t
linear LensVL s t a b
l)
{-# INLINE lensVL #-}
toLensVL :: Is k A_Lens => Optic k is s t a b -> LensVL s t a b
toLensVL :: forall k (is :: IxList) s t a b.
Is k A_Lens =>
Optic k is s t a b -> LensVL s t a b
toLensVL Optic k is s t a b
o = forall (f :: * -> *) i a b. Star f i a b -> a -> f b
runStar forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. forall (p :: * -> * -> * -> *) k (is :: IxList) s t a b i.
Profunctor p =>
Optic k is s t a b -> Optic_ k p i (Curry is i) s t a b
getOptic (forall destKind srcKind (is :: IxList) s t a b.
Is srcKind destKind =>
Optic srcKind is s t a b -> Optic destKind is s t a b
castOptic @A_Lens Optic k is s t a b
o) forall a b c. Coercible a b => (b -> c) -> (a -> b) -> a -> c
.# forall (f :: * -> *) i a b. (a -> f b) -> Star f i a b
Star
{-# INLINE toLensVL #-}
withLensVL
:: Is k A_Lens
=> Optic k is s t a b
-> (LensVL s t a b -> r)
-> r
withLensVL :: forall k (is :: IxList) s t a b r.
Is k A_Lens =>
Optic k is s t a b -> (LensVL s t a b -> r) -> r
withLensVL Optic k is s t a b
o LensVL s t a b -> r
k = LensVL s t a b -> r
k (forall k (is :: IxList) s t a b.
Is k A_Lens =>
Optic k is s t a b -> LensVL s t a b
toLensVL Optic k is s t a b
o)
{-# INLINE withLensVL #-}
equality' :: Lens a b a b
equality' :: forall a b. Lens a b a b
equality' = forall s t a b. LensVL s t a b -> Lens s t a b
lensVL forall a b. (a -> b) -> a -> b
($!)
{-# INLINE equality' #-}
alongside
:: (Is k A_Lens, Is l A_Lens)
=> Optic k is s t a b
-> Optic l js s' t' a' b'
-> Lens (s, s') (t, t') (a, a') (b, b')
alongside :: forall k l (is :: IxList) s t a b (js :: IxList) s' t' a' b'.
(Is k A_Lens, Is l A_Lens) =>
Optic k is s t a b
-> Optic l js s' t' a' b' -> Lens (s, s') (t, t') (a, a') (b, b')
alongside Optic k is s t a b
l Optic l js s' t' a' b'
r = forall k (is :: IxList) s t a b r.
Is k A_Lens =>
Optic k is s t a b -> ((s -> a) -> (s -> b -> t) -> r) -> r
withLens Optic k is s t a b
l forall a b. (a -> b) -> a -> b
$ \s -> a
getl s -> b -> t
setl ->
forall k (is :: IxList) s t a b r.
Is k A_Lens =>
Optic k is s t a b -> ((s -> a) -> (s -> b -> t) -> r) -> r
withLens Optic l js s' t' a' b'
r forall a b. (a -> b) -> a -> b
$ \s' -> a'
getr s' -> b' -> t'
setr ->
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens (\(s
s, s'
s') -> (s -> a
getl s
s, s' -> a'
getr s'
s' ))
(\(s
s, s'
s') (b
b, b'
b') -> (s -> b -> t
setl s
s b
b, s' -> b' -> t'
setr s'
s' b'
b'))
{-# INLINE alongside #-}
united :: Lens' a ()
united :: forall a. Lens' a ()
united = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens (forall a b. a -> b -> a
const ()) forall a b. a -> b -> a
const
{-# INLINE united #-}