{-# LANGUAGE DataKinds #-}
module Optics.Indexed.Core
(
IxOptic(..)
, conjoined
, (%)
, (<%>)
, (%>)
, (<%)
, reindexed
, icompose
, icompose3
, icompose4
, icompose5
, icomposeN
, module Optics.IxAffineFold
, module Optics.IxAffineTraversal
, module Optics.IxFold
, module Optics.IxGetter
, module Optics.IxLens
, module Optics.IxSetter
, module Optics.IxTraversal
, FunctorWithIndex (..)
, FoldableWithIndex (..)
, itraverse_
, ifor_
, itoList
, TraversableWithIndex (..)
, ifor
) where
import Data.Profunctor.Indexed
import Optics.Internal.Indexed
import Optics.Internal.Indexed.Classes
import Optics.Internal.Optic
import Optics.AffineFold
import Optics.AffineTraversal
import Optics.Fold
import Optics.Getter
import Optics.IxAffineFold
import Optics.IxAffineTraversal
import Optics.IxFold
import Optics.IxGetter
import Optics.IxLens
import Optics.IxSetter
import Optics.IxTraversal
import Optics.Lens
import Optics.Setter
import Optics.Traversal
infixl 9 <%>
(<%>)
:: (JoinKinds k l m, IxOptic m s t a b, is `HasSingleIndex` i, js `HasSingleIndex` j)
=> Optic k is s t u v
-> Optic l js u v a b
-> Optic m (WithIx (i, j)) s t a b
Optic k is s t u v
o <%> :: Optic k is s t u v
-> Optic l js u v a b -> Optic m (WithIx (i, j)) s t a b
<%> Optic l js u v a b
o' = (i -> j -> (i, j))
-> Optic m '[i, j] s t a b -> Optic m (WithIx (i, j)) s t a b
forall i j ix k s t a b.
(i -> j -> ix)
-> Optic k '[i, j] s t a b -> Optic k (WithIx ix) s t a b
icompose (,) (Optic k is s t u v
o Optic k is s t u v -> Optic l js u v a b -> Optic m '[i, j] s t a b
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic l js u v a b
o')
{-# INLINE (<%>) #-}
infixl 9 %>
(%>)
:: (JoinKinds k l m, IxOptic k s t u v, NonEmptyIndices is)
=> Optic k is s t u v
-> Optic l js u v a b
-> Optic m js s t a b
Optic k is s t u v
o %> :: Optic k is s t u v -> Optic l js u v a b -> Optic m js s t a b
%> Optic l js u v a b
o' = Optic k is s t u v -> Optic k '[] s t u v
forall k s t a b (is :: IxList).
(IxOptic k s t a b, NonEmptyIndices is) =>
Optic k is s t a b -> Optic k '[] s t a b
noIx Optic k is s t u v
o Optic k '[] s t u v -> Optic l js u v a b -> Optic m js s t a b
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic l js u v a b
o'
{-# INLINE (%>) #-}
infixl 9 <%
(<%)
:: (JoinKinds k l m, IxOptic l u v a b, NonEmptyIndices js)
=> Optic k is s t u v
-> Optic l js u v a b
-> Optic m is s t a b
Optic k is s t u v
o <% :: Optic k is s t u v -> Optic l js u v a b -> Optic m is s t a b
<% Optic l js u v a b
o' = Optic k is s t u v
o Optic k is s t u v -> Optic l '[] u v a b -> Optic m is s t a b
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic l js u v a b -> Optic l '[] u v a b
forall k s t a b (is :: IxList).
(IxOptic k s t a b, NonEmptyIndices is) =>
Optic k is s t a b -> Optic k '[] s t a b
noIx Optic l js u v a b
o'
{-# INLINE (<%) #-}
reindexed
:: is `HasSingleIndex` i
=> (i -> j)
-> Optic k is s t a b
-> Optic k (WithIx j) s t a b
reindexed :: (i -> j) -> Optic k is s t a b -> Optic k (WithIx j) s t a b
reindexed = (i -> j) -> Optic k is s t a b -> Optic k (WithIx j) s t a b
forall k i (is :: IxList) s t a b.
(CurryCompose is, NonEmptyIndices is) =>
Curry is i -> Optic k is s t a b -> Optic k (WithIx i) s t a b
icomposeN
{-# INLINE reindexed #-}
icompose
:: (i -> j -> ix)
-> Optic k '[i, j] s t a b
-> Optic k (WithIx ix) s t a b
icompose :: (i -> j -> ix)
-> Optic k '[i, j] s t a b -> Optic k (WithIx ix) s t a b
icompose = (i -> j -> ix)
-> Optic k '[i, j] s t a b -> Optic k (WithIx ix) s t a b
forall k i (is :: IxList) s t a b.
(CurryCompose is, NonEmptyIndices is) =>
Curry is i -> Optic k is s t a b -> Optic k (WithIx i) s t a b
icomposeN
{-# INLINE icompose #-}
icompose3
:: (i1 -> i2 -> i3 -> ix)
-> Optic k '[i1, i2, i3] s t a b
-> Optic k (WithIx ix) s t a b
icompose3 :: (i1 -> i2 -> i3 -> ix)
-> Optic k '[i1, i2, i3] s t a b -> Optic k (WithIx ix) s t a b
icompose3 = (i1 -> i2 -> i3 -> ix)
-> Optic k '[i1, i2, i3] s t a b -> Optic k (WithIx ix) s t a b
forall k i (is :: IxList) s t a b.
(CurryCompose is, NonEmptyIndices is) =>
Curry is i -> Optic k is s t a b -> Optic k (WithIx i) s t a b
icomposeN
{-# INLINE icompose3 #-}
icompose4
:: (i1 -> i2 -> i3 -> i4 -> ix)
-> Optic k '[i1, i2, i3, i4] s t a b
-> Optic k (WithIx ix) s t a b
icompose4 :: (i1 -> i2 -> i3 -> i4 -> ix)
-> Optic k '[i1, i2, i3, i4] s t a b -> Optic k (WithIx ix) s t a b
icompose4 = (i1 -> i2 -> i3 -> i4 -> ix)
-> Optic k '[i1, i2, i3, i4] s t a b -> Optic k (WithIx ix) s t a b
forall k i (is :: IxList) s t a b.
(CurryCompose is, NonEmptyIndices is) =>
Curry is i -> Optic k is s t a b -> Optic k (WithIx i) s t a b
icomposeN
{-# INLINE icompose4 #-}
icompose5
:: (i1 -> i2 -> i3 -> i4 -> i5 -> ix)
-> Optic k '[i1, i2, i3, i4, i5] s t a b
-> Optic k (WithIx ix) s t a b
icompose5 :: (i1 -> i2 -> i3 -> i4 -> i5 -> ix)
-> Optic k '[i1, i2, i3, i4, i5] s t a b
-> Optic k (WithIx ix) s t a b
icompose5 = (i1 -> i2 -> i3 -> i4 -> i5 -> ix)
-> Optic k '[i1, i2, i3, i4, i5] s t a b
-> Optic k (WithIx ix) s t a b
forall k i (is :: IxList) s t a b.
(CurryCompose is, NonEmptyIndices is) =>
Curry is i -> Optic k is s t a b -> Optic k (WithIx i) s t a b
icomposeN
{-# INLINE icompose5 #-}
icomposeN
:: forall k i is s t a b
. (CurryCompose is, NonEmptyIndices is)
=> Curry is i
-> Optic k is s t a b
-> Optic k (WithIx i) s t a b
icomposeN :: Curry is i -> Optic k is s t a b -> Optic k (WithIx i) s t a b
icomposeN Curry is i
f (Optic forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ k p i (Curry is i) s t a b
o) = (forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ k p i (Curry (WithIx i) i) s t a b)
-> Optic k (WithIx i) s t a b
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 (((i -> i) -> Curry is i) -> p (Curry is i) s t -> p (i -> i) s t
forall (p :: * -> * -> * -> *) j i a b.
Profunctor p =>
(j -> i) -> p i a b -> p j a b
ixcontramap (\i -> i
ij -> (i -> i) -> Curry is i -> Curry is i
forall (xs :: IxList) i j.
CurryCompose xs =>
(i -> j) -> Curry xs i -> Curry xs j
composeN @is i -> i
ij Curry is i
f) (p (Curry is i) s t -> p (i -> i) s t)
-> (p i a b -> p (Curry is i) s t) -> p i a b -> p (i -> i) s t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p i a b -> p (Curry is i) s t
forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ k p i (Curry is i) s t a b
o)
{-# INLINE icomposeN #-}
class IxOptic k s t a b where
noIx
:: NonEmptyIndices is
=> Optic k is s t a b
-> Optic k NoIx s t a b
instance (s ~ t, a ~ b) => IxOptic A_Getter s t a b where
noIx :: Optic A_Getter is s t a b -> Optic A_Getter '[] s t a b
noIx Optic A_Getter is s t a b
o = (s -> a) -> Getter s a
forall s a. (s -> a) -> Getter s a
to (Optic' A_Getter is s a -> s -> a
forall k (is :: IxList) s a.
Is k A_Getter =>
Optic' k is s a -> s -> a
view Optic' A_Getter is s a
Optic A_Getter is s t a b
o)
{-# INLINE noIx #-}
instance IxOptic A_Lens s t a b where
noIx :: Optic A_Lens is s t a b -> Optic A_Lens '[] s t a b
noIx Optic A_Lens is s t a b
o = LensVL s t a b -> Optic A_Lens '[] s t a b
forall s t a b. LensVL s t a b -> Lens s t a b
lensVL (Optic A_Lens is s t a b -> LensVL s t a b
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 A_Lens is s t a b
o)
{-# INLINE noIx #-}
instance IxOptic An_AffineTraversal s t a b where
noIx :: Optic An_AffineTraversal is s t a b
-> Optic An_AffineTraversal '[] s t a b
noIx Optic An_AffineTraversal is s t a b
o = AffineTraversalVL s t a b -> Optic An_AffineTraversal '[] s t a b
forall s t a b.
AffineTraversalVL s t a b -> AffineTraversal s t a b
atraversalVL (Optic An_AffineTraversal is s t a b
-> (forall r. r -> f r) -> (a -> f b) -> s -> f t
forall k (f :: * -> *) (is :: IxList) s t a b.
(Is k An_AffineTraversal, Functor f) =>
Optic k is s t a b
-> (forall r. r -> f r) -> (a -> f b) -> s -> f t
atraverseOf Optic An_AffineTraversal is s t a b
o)
{-# INLINE noIx #-}
instance (s ~ t, a ~ b) => IxOptic An_AffineFold s t a b where
noIx :: Optic An_AffineFold is s t a b -> Optic An_AffineFold '[] s t a b
noIx Optic An_AffineFold is s t a b
o = (s -> Maybe a) -> AffineFold s a
forall s a. (s -> Maybe a) -> AffineFold s a
afolding (Optic' An_AffineFold is s a -> s -> Maybe a
forall k (is :: IxList) s a.
Is k An_AffineFold =>
Optic' k is s a -> s -> Maybe a
preview Optic' An_AffineFold is s a
Optic An_AffineFold is s t a b
o)
{-# INLINE noIx #-}
instance IxOptic A_Traversal s t a b where
noIx :: Optic A_Traversal is s t a b -> Optic A_Traversal '[] s t a b
noIx Optic A_Traversal is s t a b
o = TraversalVL s t a b -> Optic A_Traversal '[] s t a b
forall s t a b. TraversalVL s t a b -> Traversal s t a b
traversalVL (Optic A_Traversal is s t a b -> (a -> f b) -> s -> f t
forall k (f :: * -> *) (is :: IxList) s t a b.
(Is k A_Traversal, Applicative f) =>
Optic k is s t a b -> (a -> f b) -> s -> f t
traverseOf Optic A_Traversal is s t a b
o)
{-# INLINE noIx #-}
instance (s ~ t, a ~ b) => IxOptic A_Fold s t a b where
noIx :: Optic A_Fold is s t a b -> Optic A_Fold '[] s t a b
noIx Optic A_Fold is s t a b
o = (forall (f :: * -> *). Applicative f => (a -> f Any) -> s -> f ())
-> Fold s a
forall a u s v.
(forall (f :: * -> *). Applicative f => (a -> f u) -> s -> f v)
-> Fold s a
foldVL (Optic' A_Fold is s a -> (a -> f Any) -> s -> f ()
forall k (f :: * -> *) (is :: IxList) s a r.
(Is k A_Fold, Applicative f) =>
Optic' k is s a -> (a -> f r) -> s -> f ()
traverseOf_ Optic' A_Fold is s a
Optic A_Fold is s t a b
o)
{-# INLINE noIx #-}
instance IxOptic A_Setter s t a b where
noIx :: Optic A_Setter is s t a b -> Optic A_Setter '[] s t a b
noIx Optic A_Setter is s t a b
o = ((a -> b) -> s -> t) -> Optic A_Setter '[] s t a b
forall a b s t. ((a -> b) -> s -> t) -> Setter s t a b
sets (Optic A_Setter is s t a b -> (a -> b) -> s -> t
forall k (is :: IxList) s t a b.
Is k A_Setter =>
Optic k is s t a b -> (a -> b) -> s -> t
over Optic A_Setter is s t a b
o)
{-# INLINE noIx #-}