{-# LANGUAGE DataKinds #-}
module Optics.IxTraversal
(
IxTraversal
, IxTraversal'
, itraversalVL
, itraverseOf
, itraversed
, ignored
, elementsOf
, elements
, elementOf
, element
, iforOf
, imapAccumLOf
, imapAccumROf
, iscanl1Of
, iscanr1Of
, ifailover
, ifailover'
, indices
, ibackwards
, ipartsOf
, isingular
, iadjoin
, A_Traversal
, IxTraversalVL
, IxTraversalVL'
, TraversableWithIndex(..)
) where
import Control.Applicative.Backwards
import Control.Monad.Trans.State
import Data.Functor.Identity
import Data.Profunctor.Indexed
import Optics.Internal.Indexed
import Optics.Internal.Indexed.Classes
import Optics.Internal.IxTraversal
import Optics.Internal.Optic
import Optics.Internal.Utils
import Optics.IxAffineTraversal
import Optics.IxLens
import Optics.IxFold
import Optics.ReadOnly
import Optics.Traversal
type IxTraversal i s t a b = Optic A_Traversal (WithIx i) s t a b
type IxTraversal' i s a = Optic' A_Traversal (WithIx i) s a
type IxTraversalVL i s t a b =
forall f. Applicative f => (i -> a -> f b) -> s -> f t
type IxTraversalVL' i s a = IxTraversalVL i s s a a
itraversalVL :: IxTraversalVL i s t a b -> IxTraversal i s t a b
itraversalVL :: forall i s t a b. IxTraversalVL i s t a b -> IxTraversal i s t a b
itraversalVL IxTraversalVL i s t a b
t = 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 :: * -> * -> * -> *) i a b s t j.
Traversing p =>
(forall (f :: * -> *).
Applicative f =>
(i -> a -> f b) -> s -> f t)
-> p j a b -> p (i -> j) s t
iwander IxTraversalVL i s t a b
t)
{-# INLINE itraversalVL #-}
itraverseOf
:: (Is k A_Traversal, Applicative f, is `HasSingleIndex` i)
=> Optic k is s t a b
-> (i -> a -> f b) -> s -> f t
itraverseOf :: forall k (f :: * -> *) (is :: IxList) i s t a b.
(Is k A_Traversal, Applicative f, HasSingleIndex is i) =>
Optic k is s t a b -> (i -> a -> f b) -> s -> f t
itraverseOf Optic k is s t a b
o = \i -> a -> f b
f ->
forall (f :: * -> *) i a b. IxStar f i a b -> i -> a -> f b
runIxStar (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_Traversal Optic k is s t a b
o) (forall (f :: * -> *) i a b. (i -> a -> f b) -> IxStar f i a b
IxStar i -> a -> f b
f)) forall a. a -> a
id
{-# INLINE itraverseOf #-}
iforOf
:: (Is k A_Traversal, Applicative f, is `HasSingleIndex` i)
=> Optic k is s t a b
-> s -> (i -> a -> f b) -> f t
iforOf :: forall k (f :: * -> *) (is :: IxList) i s t a b.
(Is k A_Traversal, Applicative f, HasSingleIndex is i) =>
Optic k is s t a b -> s -> (i -> a -> f b) -> f t
iforOf = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (f :: * -> *) (is :: IxList) i s t a b.
(Is k A_Traversal, Applicative f, HasSingleIndex is i) =>
Optic k is s t a b -> (i -> a -> f b) -> s -> f t
itraverseOf
{-# INLINE iforOf #-}
imapAccumLOf
:: (Is k A_Traversal, is `HasSingleIndex` i)
=> Optic k is s t a b
-> (i -> acc -> a -> (b, acc)) -> acc -> s -> (t, acc)
imapAccumLOf :: forall k (is :: IxList) i s t a b acc.
(Is k A_Traversal, HasSingleIndex is i) =>
Optic k is s t a b
-> (i -> acc -> a -> (b, acc)) -> acc -> s -> (t, acc)
imapAccumLOf Optic k is s t a b
o = \i -> acc -> a -> (b, acc)
f acc
acc0 s
s ->
let g :: i -> a -> StateT acc Identity b
g i
i a
a = forall (m :: * -> *) s a. Monad m => (s -> (a, s)) -> StateT s m a
state forall a b. (a -> b) -> a -> b
$ \acc
acc -> i -> acc -> a -> (b, acc)
f i
i acc
acc a
a
in forall s a. State s a -> s -> (a, s)
runState (forall k (f :: * -> *) (is :: IxList) i s t a b.
(Is k A_Traversal, Applicative f, HasSingleIndex is i) =>
Optic k is s t a b -> (i -> a -> f b) -> s -> f t
itraverseOf Optic k is s t a b
o i -> a -> StateT acc Identity b
g s
s) acc
acc0
{-# INLINE imapAccumLOf #-}
imapAccumROf
:: (Is k A_Traversal, is `HasSingleIndex` i)
=> Optic k is s t a b
-> (i -> acc -> a -> (b, acc)) -> acc -> s -> (t, acc)
imapAccumROf :: forall k (is :: IxList) i s t a b acc.
(Is k A_Traversal, HasSingleIndex is i) =>
Optic k is s t a b
-> (i -> acc -> a -> (b, acc)) -> acc -> s -> (t, acc)
imapAccumROf = forall k (is :: IxList) i s t a b acc.
(Is k A_Traversal, HasSingleIndex is i) =>
Optic k is s t a b
-> (i -> acc -> a -> (b, acc)) -> acc -> s -> (t, acc)
imapAccumLOf forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (is :: IxList) i s t a b.
(Is k A_Traversal, HasSingleIndex is i) =>
Optic k is s t a b -> IxTraversal i s t a b
ibackwards
{-# INLINE imapAccumROf #-}
iscanl1Of
:: (Is k A_Traversal, is `HasSingleIndex` i)
=> Optic k is s t a a
-> (i -> a -> a -> a) -> s -> t
iscanl1Of :: forall k (is :: IxList) i s t a.
(Is k A_Traversal, HasSingleIndex is i) =>
Optic k is s t a a -> (i -> a -> a -> a) -> s -> t
iscanl1Of Optic k is s t a a
o = \i -> a -> a -> a
f ->
let step :: i -> Maybe a -> a -> (a, Maybe a)
step i
i Maybe a
ms a
a = case Maybe a
ms of
Maybe a
Nothing -> (a
a, forall a. a -> Maybe a
Just a
a)
Just a
s -> let r :: a
r = i -> a -> a -> a
f i
i a
s a
a in (a
r, forall a. a -> Maybe a
Just a
r)
in forall a b. (a, b) -> a
fst forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (is :: IxList) i s t a b acc.
(Is k A_Traversal, HasSingleIndex is i) =>
Optic k is s t a b
-> (i -> acc -> a -> (b, acc)) -> acc -> s -> (t, acc)
imapAccumLOf Optic k is s t a a
o i -> Maybe a -> a -> (a, Maybe a)
step forall a. Maybe a
Nothing
{-# INLINE iscanl1Of #-}
iscanr1Of
:: (Is k A_Traversal, is `HasSingleIndex` i)
=> Optic k is s t a a
-> (i -> a -> a -> a) -> s -> t
iscanr1Of :: forall k (is :: IxList) i s t a.
(Is k A_Traversal, HasSingleIndex is i) =>
Optic k is s t a a -> (i -> a -> a -> a) -> s -> t
iscanr1Of Optic k is s t a a
o i -> a -> a -> a
f = forall a b. (a, b) -> a
fst forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (is :: IxList) i s t a b acc.
(Is k A_Traversal, HasSingleIndex is i) =>
Optic k is s t a b
-> (i -> acc -> a -> (b, acc)) -> acc -> s -> (t, acc)
imapAccumROf Optic k is s t a a
o i -> Maybe a -> a -> (a, Maybe a)
step forall a. Maybe a
Nothing
where
step :: i -> Maybe a -> a -> (a, Maybe a)
step i
i Maybe a
ms a
a = case Maybe a
ms of
Maybe a
Nothing -> (a
a, forall a. a -> Maybe a
Just a
a)
Just a
s -> let r :: a
r = i -> a -> a -> a
f i
i a
a a
s in (a
r, forall a. a -> Maybe a
Just a
r)
{-# INLINE iscanr1Of #-}
ifailover
:: (Is k A_Traversal, is `HasSingleIndex` i)
=> Optic k is s t a b
-> (i -> a -> b) -> s -> Maybe t
ifailover :: forall k (is :: IxList) i s t a b.
(Is k A_Traversal, HasSingleIndex is i) =>
Optic k is s t a b -> (i -> a -> b) -> s -> Maybe t
ifailover Optic k is s t a b
o = \i -> a -> b
f s
s ->
let OrT Bool
visited Identity t
t = forall k (f :: * -> *) (is :: IxList) i s t a b.
(Is k A_Traversal, Applicative f, HasSingleIndex is i) =>
Optic k is s t a b -> (i -> a -> f b) -> s -> f t
itraverseOf Optic k is s t a b
o (\i
i -> forall (f :: * -> *) a. f a -> OrT f a
wrapOrT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Identity a
Identity forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. i -> a -> b
f i
i) s
s
in if Bool
visited
then forall a. a -> Maybe a
Just (forall a. Identity a -> a
runIdentity Identity t
t)
else forall a. Maybe a
Nothing
{-# INLINE ifailover #-}
ifailover'
:: (Is k A_Traversal, is `HasSingleIndex` i)
=> Optic k is s t a b
-> (i -> a -> b) -> s -> Maybe t
ifailover' :: forall k (is :: IxList) i s t a b.
(Is k A_Traversal, HasSingleIndex is i) =>
Optic k is s t a b -> (i -> a -> b) -> s -> Maybe t
ifailover' Optic k is s t a b
o = \i -> a -> b
f s
s ->
let OrT Bool
visited Identity' t
t = forall k (f :: * -> *) (is :: IxList) i s t a b.
(Is k A_Traversal, Applicative f, HasSingleIndex is i) =>
Optic k is s t a b -> (i -> a -> f b) -> s -> f t
itraverseOf Optic k is s t a b
o (\i
i -> forall (f :: * -> *) a. f a -> OrT f a
wrapOrT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Identity' a
wrapIdentity' forall b c a. (b -> c) -> (a -> b) -> a -> c
. i -> a -> b
f i
i) s
s
in if Bool
visited
then forall a. a -> Maybe a
Just (forall a. Identity' a -> a
unwrapIdentity' Identity' t
t)
else forall a. Maybe a
Nothing
{-# INLINE ifailover' #-}
itraversed
:: TraversableWithIndex i f
=> IxTraversal i (f a) (f b) a b
itraversed :: forall i (f :: * -> *) a b.
TraversableWithIndex i f =>
IxTraversal i (f a) (f b) a b
itraversed = 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 :: * -> * -> * -> *) i (f :: * -> *) j a b.
(Traversing p, TraversableWithIndex i f) =>
Optic__ p j (i -> j) (f a) (f b) a b
itraversed__
{-# INLINE itraversed #-}
indices
:: (Is k A_Traversal, is `HasSingleIndex` i)
=> (i -> Bool)
-> Optic k is s t a a
-> IxTraversal i s t a a
indices :: forall k (is :: IxList) i s t a.
(Is k A_Traversal, HasSingleIndex is i) =>
(i -> Bool) -> Optic k is s t a a -> IxTraversal i s t a a
indices i -> Bool
p Optic k is s t a a
o = forall i s t a b. IxTraversalVL i s t a b -> IxTraversal i s t a b
itraversalVL forall a b. (a -> b) -> a -> b
$ \i -> a -> f a
f ->
forall k (f :: * -> *) (is :: IxList) i s t a b.
(Is k A_Traversal, Applicative f, HasSingleIndex is i) =>
Optic k is s t a b -> (i -> a -> f b) -> s -> f t
itraverseOf Optic k is s t a a
o forall a b. (a -> b) -> a -> b
$ \i
i a
a -> if i -> Bool
p i
i then i -> a -> f a
f i
i a
a else forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a
{-# INLINE indices #-}
ibackwards
:: (Is k A_Traversal, is `HasSingleIndex` i)
=> Optic k is s t a b
-> IxTraversal i s t a b
ibackwards :: forall k (is :: IxList) i s t a b.
(Is k A_Traversal, HasSingleIndex is i) =>
Optic k is s t a b -> IxTraversal i s t a b
ibackwards Optic k is s t a b
o = forall (is :: IxList) i k s t a b.
HasSingleIndex is i =>
Optic k '[] s t a b -> Optic k is s t a b -> Optic k is s t a b
conjoined (forall k (is :: IxList) s t a b.
Is k A_Traversal =>
Optic k is s t a b -> Traversal s t a b
backwards Optic k is s t a b
o) forall a b. (a -> b) -> a -> b
$ forall i s t a b. IxTraversalVL i s t a b -> IxTraversal i s t a b
itraversalVL forall a b. (a -> b) -> a -> b
$ \i -> a -> f b
f ->
forall {k} (f :: k -> *) (a :: k). Backwards f a -> f a
forwards forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. forall k (f :: * -> *) (is :: IxList) i s t a b.
(Is k A_Traversal, Applicative f, HasSingleIndex is i) =>
Optic k is s t a b -> (i -> a -> f b) -> s -> f t
itraverseOf Optic k is s t a b
o (\i
i -> forall {k} (f :: k -> *) (a :: k). f a -> Backwards f a
Backwards forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. i -> a -> f b
f i
i)
{-# INLINE ibackwards #-}
elementsOf
:: Is k A_Traversal
=> Optic k is s t a a
-> (Int -> Bool)
-> IxTraversal Int s t a a
elementsOf :: forall k (is :: IxList) s t a.
Is k A_Traversal =>
Optic k is s t a a -> (Int -> Bool) -> IxTraversal Int s t a a
elementsOf Optic k is s t a a
o = \Int -> Bool
p -> forall i s t a b. IxTraversalVL i s t a b -> IxTraversal i s t a b
itraversalVL forall a b. (a -> b) -> a -> b
$ \Int -> a -> f a
f ->
forall {k} a (f :: k -> *) (b :: k) s (t :: k).
((a -> Indexing f b) -> s -> Indexing f t)
-> (Int -> a -> f b) -> s -> f t
indexing (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 k is s t a a
o) forall a b. (a -> b) -> a -> b
$ \Int
i a
a -> if Int -> Bool
p Int
i then Int -> a -> f a
f Int
i a
a else forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a
{-# INLINE elementsOf #-}
elements :: Traversable f => (Int -> Bool) -> IxTraversal' Int (f a) a
elements :: forall (f :: * -> *) a.
Traversable f =>
(Int -> Bool) -> IxTraversal' Int (f a) a
elements = forall k (is :: IxList) s t a.
Is k A_Traversal =>
Optic k is s t a a -> (Int -> Bool) -> IxTraversal Int s t a a
elementsOf forall (t :: * -> *) a b.
Traversable t =>
Traversal (t a) (t b) a b
traversed
{-# INLINE elements #-}
elementOf
:: Is k A_Traversal
=> Optic' k is s a
-> Int
-> IxAffineTraversal' Int s a
elementOf :: forall k (is :: IxList) s a.
Is k A_Traversal =>
Optic' k is s a -> Int -> IxAffineTraversal' Int s a
elementOf Optic' k is s a
o = \Int
i -> forall k (is :: IxList) i s a.
(Is k A_Traversal, HasSingleIndex is i) =>
Optic' k is s a -> IxAffineTraversal' i s a
isingular forall a b. (a -> b) -> a -> b
$ forall k (is :: IxList) s t a.
Is k A_Traversal =>
Optic k is s t a a -> (Int -> Bool) -> IxTraversal Int s t a a
elementsOf Optic' k is s a
o (forall a. Eq a => a -> a -> Bool
== Int
i)
{-# INLINE elementOf #-}
element :: Traversable f => Int -> IxAffineTraversal' Int (f a) a
element :: forall (f :: * -> *) a.
Traversable f =>
Int -> IxAffineTraversal' Int (f a) a
element = forall k (is :: IxList) s a.
Is k A_Traversal =>
Optic' k is s a -> Int -> IxAffineTraversal' Int s a
elementOf forall (t :: * -> *) a b.
Traversable t =>
Traversal (t a) (t b) a b
traversed
{-# INLINE element #-}
ipartsOf
:: forall k is i s t a. (Is k A_Traversal, is `HasSingleIndex` i)
=> Optic k is s t a a
-> IxLens [i] s t [a] [a]
ipartsOf :: forall k (is :: IxList) i s t a.
(Is k A_Traversal, HasSingleIndex is i) =>
Optic k is s t a a -> IxLens [i] s t [a] [a]
ipartsOf Optic k is s t a a
o = forall (is :: IxList) i k s t a b.
HasSingleIndex is i =>
Optic k '[] s t a b -> Optic k is s t a b -> Optic k is s t a b
conjoined (forall k (is :: IxList) s t a.
Is k A_Traversal =>
Optic k is s t a a -> Lens s t [a] [a]
partsOf Optic k is s t a a
o) forall a b. (a -> b) -> a -> b
$ forall i s t a b. IxLensVL i s t a b -> IxLens i s t a b
ilensVL forall a b. (a -> b) -> a -> b
$ \[i] -> [a] -> f [a]
f s
s ->
forall s a. State s a -> s -> a
evalState (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 k is s t a a
o forall {m :: * -> *} {b}. Monad m => b -> StateT [b] m b
update s
s)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry' [i] -> [a] -> f [a]
f (forall a b. [(a, b)] -> ([a], [b])
unzip forall a b. (a -> b) -> a -> b
$ forall k (is :: IxList) i s a.
(Is k A_Fold, HasSingleIndex is i) =>
Optic' k is s a -> s -> [(i, a)]
itoListOf (forall k s t a b (is :: IxList).
ToReadOnly k s t a b =>
Optic k is s t a b -> Optic' (ReadOnlyOptic k) is s a
getting forall a b. (a -> b) -> a -> b
$ 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_Traversal Optic k is s t a a
o) s
s)
where
update :: b -> StateT [b] m b
update b
a = forall (m :: * -> *) s. Monad m => StateT s m s
get forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
[] -> forall (f :: * -> *) a. Applicative f => a -> f a
pure b
a
b
a' : [b]
as' -> forall (m :: * -> *) s. Monad m => s -> StateT s m ()
put [b]
as' forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (f :: * -> *) a. Applicative f => a -> f a
pure b
a'
{-# INLINE ipartsOf #-}
isingular
:: forall k is i s a. (Is k A_Traversal, is `HasSingleIndex` i)
=> Optic' k is s a
-> IxAffineTraversal' i s a
isingular :: forall k (is :: IxList) i s a.
(Is k A_Traversal, HasSingleIndex is i) =>
Optic' k is s a -> IxAffineTraversal' i s a
isingular Optic' k is s a
o = forall (is :: IxList) i k s t a b.
HasSingleIndex is i =>
Optic k '[] s t a b -> Optic k is s t a b -> Optic k is s t a b
conjoined (forall k (is :: IxList) s a.
Is k A_Traversal =>
Optic' k is s a -> AffineTraversal' s a
singular Optic' k is s a
o) forall a b. (a -> b) -> a -> b
$ forall i s t a b.
IxAffineTraversalVL i s t a b -> IxAffineTraversal i s t a b
iatraversalVL forall a b. (a -> b) -> a -> b
$ \forall r. r -> f r
point i -> a -> f a
f s
s ->
case forall k (is :: IxList) i s a.
(Is k A_Fold, HasSingleIndex is i) =>
Optic' k is s a -> s -> Maybe (i, a)
iheadOf (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_Traversal Optic' k is s a
o) s
s of
Maybe (i, a)
Nothing -> forall r. r -> f r
point s
s
Just (i
i, a
a) -> forall s a. State s a -> s -> a
evalState (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' k is s a
o forall {m :: * -> *} {b}. Monad m => b -> StateT (Maybe b) m b
update s
s) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Maybe a
Just forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> i -> a -> f a
f i
i a
a
where
update :: b -> StateT (Maybe b) m b
update b
a = forall (m :: * -> *) s. Monad m => StateT s m s
get forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Just b
a' -> forall (m :: * -> *) s. Monad m => s -> StateT s m ()
put forall a. Maybe a
Nothing forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (f :: * -> *) a. Applicative f => a -> f a
pure b
a'
Maybe b
Nothing -> forall (f :: * -> *) a. Applicative f => a -> f a
pure b
a
{-# INLINE isingular #-}
iadjoin
:: (Is k A_Traversal, Is l A_Traversal, is `HasSingleIndex` i)
=> Optic' k is s a
-> Optic' l is s a
-> IxTraversal' i s a
iadjoin :: forall k l (is :: IxList) i s a.
(Is k A_Traversal, Is l A_Traversal, HasSingleIndex is i) =>
Optic' k is s a -> Optic' l is s a -> IxTraversal' i s a
iadjoin Optic' k is s a
o1 Optic' l is s a
o2 = forall (is :: IxList) i k s t a b.
HasSingleIndex is i =>
Optic k '[] s t a b -> Optic k is s t a b -> Optic k is s t a b
conjoined (forall k l (is :: IxList) s a (js :: IxList).
(Is k A_Traversal, Is l A_Traversal) =>
Optic' k is s a -> Optic' l js s a -> Traversal' s a
adjoin Optic' k is s a
o1 Optic' l is s a
o2) (Traversal s s [(i, a)] [(i, a)]
combined 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
% forall (t :: * -> *) a b.
Traversable t =>
Traversal (t a) (t b) a b
traversed 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
% forall i (f :: * -> *) a b.
TraversableWithIndex i f =>
IxTraversal i (f a) (f b) a b
itraversed)
where
combined :: Traversal s s [(i, a)] [(i, a)]
combined = forall s t a b. TraversalVL s t a b -> Traversal s t a b
traversalVL forall a b. (a -> b) -> a -> b
$ \[(i, a)] -> f [(i, a)]
f s
s0 ->
(\[(i, a)]
r1 [(i, a)]
r2 ->
let s1 :: s
s1 = forall s a. State s a -> s -> a
evalState (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' k is s a
o1 forall {m :: * -> *} {b} {a}. Monad m => b -> StateT [(a, b)] m b
update s
s0) [(i, a)]
r1
s2 :: s
s2 = forall s a. State s a -> s -> a
evalState (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' l is s a
o2 forall {m :: * -> *} {b} {a}. Monad m => b -> StateT [(a, b)] m b
update s
s1) [(i, a)]
r2
in s
s2
)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(i, a)] -> f [(i, a)]
f (forall k (is :: IxList) i s a.
(Is k A_Fold, HasSingleIndex is i) =>
Optic' k is s a -> s -> [(i, a)]
itoListOf (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_Traversal Optic' k is s a
o1) s
s0)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [(i, a)] -> f [(i, a)]
f (forall k (is :: IxList) i s a.
(Is k A_Fold, HasSingleIndex is i) =>
Optic' k is s a -> s -> [(i, a)]
itoListOf (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_Traversal Optic' l is s a
o2) s
s0)
update :: b -> StateT [(a, b)] m b
update b
a = forall (m :: * -> *) s. Monad m => StateT s m s
get forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
(a
_, b
a') : [(a, b)]
as' -> forall (m :: * -> *) s. Monad m => s -> StateT s m ()
put [(a, b)]
as' forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (f :: * -> *) a. Applicative f => a -> f a
pure b
a'
[] -> forall (f :: * -> *) a. Applicative f => a -> f a
pure b
a
infixr 6 `iadjoin`
{-# INLINE [1] iadjoin #-}
{-# RULES
"iadjoin_12_3" forall o1 o2 o3. iadjoin o1 (iadjoin o2 o3) = iadjoin3 o1 o2 o3
"iadjoin_21_3" forall o1 o2 o3. iadjoin (iadjoin o1 o2) o3 = iadjoin3 o1 o2 o3
"iadjoin_13_4" forall o1 o2 o3 o4. iadjoin o1 (iadjoin3 o2 o3 o4) = iadjoin4 o1 o2 o3 o4
"iadjoin_31_4" forall o1 o2 o3 o4. iadjoin (iadjoin3 o1 o2 o3) o4 = iadjoin4 o1 o2 o3 o4
#-}
iadjoin3
:: (Is k1 A_Traversal, Is k2 A_Traversal, Is k3 A_Traversal, is `HasSingleIndex` i )
=> Optic' k1 is s a
-> Optic' k2 is s a
-> Optic' k3 is s a
-> IxTraversal' i s a
iadjoin3 :: forall k1 k2 k3 (is :: IxList) i s a.
(Is k1 A_Traversal, Is k2 A_Traversal, Is k3 A_Traversal,
HasSingleIndex is i) =>
Optic' k1 is s a
-> Optic' k2 is s a -> Optic' k3 is s a -> IxTraversal' i s a
iadjoin3 Optic' k1 is s a
o1 Optic' k2 is s a
o2 Optic' k3 is s a
o3 = forall (is :: IxList) i k s t a b.
HasSingleIndex is i =>
Optic k '[] s t a b -> Optic k is s t a b -> Optic k is s t a b
conjoined (Optic' k1 is s a
o1 forall k l (is :: IxList) s a (js :: IxList).
(Is k A_Traversal, Is l A_Traversal) =>
Optic' k is s a -> Optic' l js s a -> Traversal' s a
`adjoin` Optic' k2 is s a
o2 forall k l (is :: IxList) s a (js :: IxList).
(Is k A_Traversal, Is l A_Traversal) =>
Optic' k is s a -> Optic' l js s a -> Traversal' s a
`adjoin` Optic' k3 is s a
o3)
(Traversal s s [(i, a)] [(i, a)]
combined 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
% forall (t :: * -> *) a b.
Traversable t =>
Traversal (t a) (t b) a b
traversed 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
% forall i (f :: * -> *) a b.
TraversableWithIndex i f =>
IxTraversal i (f a) (f b) a b
itraversed)
where
combined :: Traversal s s [(i, a)] [(i, a)]
combined = forall s t a b. TraversalVL s t a b -> Traversal s t a b
traversalVL forall a b. (a -> b) -> a -> b
$ \[(i, a)] -> f [(i, a)]
f s
s0 ->
(\[(i, a)]
r1 [(i, a)]
r2 [(i, a)]
r3 ->
let s1 :: s
s1 = forall s a. State s a -> s -> a
evalState (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' k1 is s a
o1 forall {m :: * -> *} {b} {a}. Monad m => b -> StateT [(a, b)] m b
update s
s0) [(i, a)]
r1
s2 :: s
s2 = forall s a. State s a -> s -> a
evalState (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' k2 is s a
o2 forall {m :: * -> *} {b} {a}. Monad m => b -> StateT [(a, b)] m b
update s
s1) [(i, a)]
r2
s3 :: s
s3 = forall s a. State s a -> s -> a
evalState (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' k3 is s a
o3 forall {m :: * -> *} {b} {a}. Monad m => b -> StateT [(a, b)] m b
update s
s2) [(i, a)]
r3
in s
s3
)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(i, a)] -> f [(i, a)]
f (forall k (is :: IxList) i s a.
(Is k A_Fold, HasSingleIndex is i) =>
Optic' k is s a -> s -> [(i, a)]
itoListOf (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_Traversal Optic' k1 is s a
o1) s
s0)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [(i, a)] -> f [(i, a)]
f (forall k (is :: IxList) i s a.
(Is k A_Fold, HasSingleIndex is i) =>
Optic' k is s a -> s -> [(i, a)]
itoListOf (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_Traversal Optic' k2 is s a
o2) s
s0)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [(i, a)] -> f [(i, a)]
f (forall k (is :: IxList) i s a.
(Is k A_Fold, HasSingleIndex is i) =>
Optic' k is s a -> s -> [(i, a)]
itoListOf (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_Traversal Optic' k3 is s a
o3) s
s0)
update :: b -> StateT [(a, b)] m b
update b
a = forall (m :: * -> *) s. Monad m => StateT s m s
get forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
(a
_, b
a') : [(a, b)]
as' -> forall (m :: * -> *) s. Monad m => s -> StateT s m ()
put [(a, b)]
as' forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (f :: * -> *) a. Applicative f => a -> f a
pure b
a'
[] -> forall (f :: * -> *) a. Applicative f => a -> f a
pure b
a
{-# INLINE [1] iadjoin3 #-}
{-# RULES
"iadjoin_211_4" forall o1 o2 o3 o4. iadjoin3 (iadjoin o1 o2) o3 o4 = iadjoin4 o1 o2 o3 o4
"iadjoin_121_4" forall o1 o2 o3 o4. iadjoin3 o1 (iadjoin o2 o3) o4 = iadjoin4 o1 o2 o3 o4
"iadjoin_112_4" forall o1 o2 o3 o4. iadjoin3 o1 o2 (iadjoin o3 o4) = iadjoin4 o1 o2 o3 o4
#-}
iadjoin4
:: ( Is k1 A_Traversal, Is k2 A_Traversal, Is k3 A_Traversal, Is k4 A_Traversal
, is `HasSingleIndex` i)
=> Optic' k1 is s a
-> Optic' k2 is s a
-> Optic' k3 is s a
-> Optic' k4 is s a
-> IxTraversal' i s a
iadjoin4 :: forall k1 k2 k3 k4 (is :: IxList) i s a.
(Is k1 A_Traversal, Is k2 A_Traversal, Is k3 A_Traversal,
Is k4 A_Traversal, HasSingleIndex is i) =>
Optic' k1 is s a
-> Optic' k2 is s a
-> Optic' k3 is s a
-> Optic' k4 is s a
-> IxTraversal' i s a
iadjoin4 Optic' k1 is s a
o1 Optic' k2 is s a
o2 Optic' k3 is s a
o3 Optic' k4 is s a
o4 = forall (is :: IxList) i k s t a b.
HasSingleIndex is i =>
Optic k '[] s t a b -> Optic k is s t a b -> Optic k is s t a b
conjoined (Optic' k1 is s a
o1 forall k l (is :: IxList) s a (js :: IxList).
(Is k A_Traversal, Is l A_Traversal) =>
Optic' k is s a -> Optic' l js s a -> Traversal' s a
`adjoin` Optic' k2 is s a
o2 forall k l (is :: IxList) s a (js :: IxList).
(Is k A_Traversal, Is l A_Traversal) =>
Optic' k is s a -> Optic' l js s a -> Traversal' s a
`adjoin` Optic' k3 is s a
o3 forall k l (is :: IxList) s a (js :: IxList).
(Is k A_Traversal, Is l A_Traversal) =>
Optic' k is s a -> Optic' l js s a -> Traversal' s a
`adjoin` Optic' k4 is s a
o4)
(Traversal s s [(i, a)] [(i, a)]
combined 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
% forall (t :: * -> *) a b.
Traversable t =>
Traversal (t a) (t b) a b
traversed 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
% forall i (f :: * -> *) a b.
TraversableWithIndex i f =>
IxTraversal i (f a) (f b) a b
itraversed)
where
combined :: Traversal s s [(i, a)] [(i, a)]
combined = forall s t a b. TraversalVL s t a b -> Traversal s t a b
traversalVL forall a b. (a -> b) -> a -> b
$ \[(i, a)] -> f [(i, a)]
f s
s0 ->
(\[(i, a)]
r1 [(i, a)]
r2 [(i, a)]
r3 [(i, a)]
r4 ->
let s1 :: s
s1 = forall s a. State s a -> s -> a
evalState (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' k1 is s a
o1 forall {m :: * -> *} {b} {a}. Monad m => b -> StateT [(a, b)] m b
update s
s0) [(i, a)]
r1
s2 :: s
s2 = forall s a. State s a -> s -> a
evalState (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' k2 is s a
o2 forall {m :: * -> *} {b} {a}. Monad m => b -> StateT [(a, b)] m b
update s
s1) [(i, a)]
r2
s3 :: s
s3 = forall s a. State s a -> s -> a
evalState (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' k3 is s a
o3 forall {m :: * -> *} {b} {a}. Monad m => b -> StateT [(a, b)] m b
update s
s2) [(i, a)]
r3
s4 :: s
s4 = forall s a. State s a -> s -> a
evalState (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' k4 is s a
o4 forall {m :: * -> *} {b} {a}. Monad m => b -> StateT [(a, b)] m b
update s
s3) [(i, a)]
r4
in s
s4
)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(i, a)] -> f [(i, a)]
f (forall k (is :: IxList) i s a.
(Is k A_Fold, HasSingleIndex is i) =>
Optic' k is s a -> s -> [(i, a)]
itoListOf (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_Traversal Optic' k1 is s a
o1) s
s0)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [(i, a)] -> f [(i, a)]
f (forall k (is :: IxList) i s a.
(Is k A_Fold, HasSingleIndex is i) =>
Optic' k is s a -> s -> [(i, a)]
itoListOf (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_Traversal Optic' k2 is s a
o2) s
s0)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [(i, a)] -> f [(i, a)]
f (forall k (is :: IxList) i s a.
(Is k A_Fold, HasSingleIndex is i) =>
Optic' k is s a -> s -> [(i, a)]
itoListOf (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_Traversal Optic' k3 is s a
o3) s
s0)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [(i, a)] -> f [(i, a)]
f (forall k (is :: IxList) i s a.
(Is k A_Fold, HasSingleIndex is i) =>
Optic' k is s a -> s -> [(i, a)]
itoListOf (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_Traversal Optic' k4 is s a
o4) s
s0)
update :: b -> StateT [(a, b)] m b
update b
a = forall (m :: * -> *) s. Monad m => StateT s m s
get forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
(a
_, b
a') : [(a, b)]
as' -> forall (m :: * -> *) s. Monad m => s -> StateT s m ()
put [(a, b)]
as' forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (f :: * -> *) a. Applicative f => a -> f a
pure b
a'
[] -> forall (f :: * -> *) a. Applicative f => a -> f a
pure b
a
{-# INLINE [1] iadjoin4 #-}