{-# 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
, 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.IxTraversal
import Optics.Internal.Optic
import Optics.Internal.Utils
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 :: IxTraversalVL i s t a b -> IxTraversal i s t a b
itraversalVL t :: IxTraversalVL i s t a b
t = (forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ A_Traversal p i (Curry (WithIx i) i) s t a b)
-> IxTraversal 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 (IxTraversalVL i s t a b -> p i a b -> p (i -> i) s t
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 :: Optic k is s t a b -> (i -> a -> f b) -> s -> f t
itraverseOf o :: Optic k is s t a b
o = \f :: i -> a -> f b
f ->
IxStar f (i -> i) s t -> (i -> i) -> s -> f t
forall (f :: * -> *) i a b. IxStar f i a b -> i -> a -> f b
runIxStar (Optic A_Traversal is s t a b
-> Optic__ (IxStar f) i (Curry is i) s t a b
forall k (is :: IxList) s t a b.
Optic k is s t a b
-> forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ k p i (Curry is i) s t a b
getOptic (Optic k is s t a b -> Optic A_Traversal is s t 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 b
o) ((i -> a -> f b) -> IxStar f i a b
forall (f :: * -> *) i a b. (i -> a -> f b) -> IxStar f i a b
IxStar i -> a -> f b
f)) i -> i
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 :: Optic k is s t a b -> s -> (i -> a -> f b) -> f t
iforOf = ((i -> a -> f b) -> s -> f t) -> s -> (i -> a -> f b) -> f t
forall a b c. (a -> b -> c) -> b -> a -> c
flip (((i -> a -> f b) -> s -> f t) -> s -> (i -> a -> f b) -> f t)
-> (Optic k is s t a b -> (i -> a -> f b) -> s -> f t)
-> Optic k is s t a b
-> s
-> (i -> a -> f b)
-> f t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Optic k is s t a b -> (i -> a -> f b) -> s -> f 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
{-# 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 :: Optic k is s t a b
-> (i -> acc -> a -> (b, acc)) -> acc -> s -> (t, acc)
imapAccumLOf o :: Optic k is s t a b
o = \f :: i -> acc -> a -> (b, acc)
f acc0 :: acc
acc0 s :: s
s ->
let g :: i -> a -> StateT acc Identity b
g i :: i
i a :: a
a = (acc -> (b, acc)) -> StateT acc Identity b
forall (m :: * -> *) s a. Monad m => (s -> (a, s)) -> StateT s m a
state ((acc -> (b, acc)) -> StateT acc Identity b)
-> (acc -> (b, acc)) -> StateT acc Identity b
forall a b. (a -> b) -> a -> b
$ \acc :: acc
acc -> i -> acc -> a -> (b, acc)
f i
i acc
acc a
a
in State acc t -> acc -> (t, acc)
forall s a. State s a -> s -> (a, s)
runState (Optic k is s t a b
-> (i -> a -> StateT acc Identity b) -> s -> State acc 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 -> 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 :: Optic k is s t a b
-> (i -> acc -> a -> (b, acc)) -> acc -> s -> (t, acc)
imapAccumROf = Optic A_Traversal (WithIx i) s t a b
-> (i -> acc -> a -> (b, acc)) -> acc -> s -> (t, acc)
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 A_Traversal (WithIx i) s t a b
-> (i -> acc -> a -> (b, acc)) -> acc -> s -> (t, acc))
-> (Optic k is s t a b -> Optic A_Traversal (WithIx i) s t a b)
-> Optic k is s t a b
-> (i -> acc -> a -> (b, acc))
-> acc
-> s
-> (t, acc)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Optic k is s t a b -> Optic A_Traversal (WithIx i) s t a b
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 :: Optic k is s t a a -> (i -> a -> a -> a) -> s -> t
iscanl1Of o :: Optic k is s t a a
o = \f :: i -> a -> a -> a
f ->
let step :: i -> Maybe a -> a -> (a, Maybe a)
step i :: i
i ms :: Maybe a
ms a :: a
a = case Maybe a
ms of
Nothing -> (a
a, a -> Maybe a
forall a. a -> Maybe a
Just a
a)
Just s :: a
s -> let r :: a
r = i -> a -> a -> a
f i
i a
s a
a in (a
r, a -> Maybe a
forall a. a -> Maybe a
Just a
r)
in (t, Maybe a) -> t
forall a b. (a, b) -> a
fst ((t, Maybe a) -> t) -> (s -> (t, Maybe a)) -> s -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Optic k is s t a a
-> (i -> Maybe a -> a -> (a, Maybe a))
-> Maybe a
-> s
-> (t, Maybe a)
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 Maybe a
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 :: Optic k is s t a a -> (i -> a -> a -> a) -> s -> t
iscanr1Of o :: Optic k is s t a a
o f :: i -> a -> a -> a
f = (t, Maybe a) -> t
forall a b. (a, b) -> a
fst ((t, Maybe a) -> t) -> (s -> (t, Maybe a)) -> s -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Optic k is s t a a
-> (i -> Maybe a -> a -> (a, Maybe a))
-> Maybe a
-> s
-> (t, Maybe a)
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 Maybe a
forall a. Maybe a
Nothing
where
step :: i -> Maybe a -> a -> (a, Maybe a)
step i :: i
i ms :: Maybe a
ms a :: a
a = case Maybe a
ms of
Nothing -> (a
a, a -> Maybe a
forall a. a -> Maybe a
Just a
a)
Just s :: a
s -> let r :: a
r = i -> a -> a -> a
f i
i a
a a
s in (a
r, a -> Maybe a
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 :: Optic k is s t a b -> (i -> a -> b) -> s -> Maybe t
ifailover o :: Optic k is s t a b
o = \f :: i -> a -> b
f s :: s
s ->
let OrT visited :: Bool
visited t :: Identity t
t = Optic k is s t a b
-> (i -> a -> OrT Identity b) -> s -> OrT Identity 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
i -> Identity b -> OrT Identity b
forall (f :: * -> *) a. f a -> OrT f a
wrapOrT (Identity b -> OrT Identity b)
-> (a -> Identity b) -> a -> OrT Identity b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> Identity b
forall a. a -> Identity a
Identity (b -> Identity b) -> (a -> b) -> a -> Identity b
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 t -> Maybe t
forall a. a -> Maybe a
Just (Identity t -> t
forall a. Identity a -> a
runIdentity Identity t
t)
else Maybe t
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' :: Optic k is s t a b -> (i -> a -> b) -> s -> Maybe t
ifailover' o :: Optic k is s t a b
o = \f :: i -> a -> b
f s :: s
s ->
let OrT visited :: Bool
visited t :: Identity' t
t = Optic k is s t a b
-> (i -> a -> OrT Identity' b) -> s -> OrT Identity' 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
i -> Identity' b -> OrT Identity' b
forall (f :: * -> *) a. f a -> OrT f a
wrapOrT (Identity' b -> OrT Identity' b)
-> (a -> Identity' b) -> a -> OrT Identity' b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> Identity' b
forall a. a -> Identity' a
wrapIdentity' (b -> Identity' b) -> (a -> b) -> a -> Identity' b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. i -> a -> b
f i
i) s
s
in if Bool
visited
then t -> Maybe t
forall a. a -> Maybe a
Just (Identity' t -> t
forall a. Identity' a -> a
unwrapIdentity' Identity' t
t)
else Maybe t
forall a. Maybe a
Nothing
{-# INLINE ifailover' #-}
itraversed
:: TraversableWithIndex i f
=> IxTraversal i (f a) (f b) a b
itraversed :: IxTraversal i (f a) (f b) a b
itraversed = (forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ A_Traversal p i (Curry (WithIx i) i) (f a) (f b) a b)
-> IxTraversal i (f a) (f b) 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 forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ A_Traversal p i (Curry (WithIx i) i) (f a) (f b) a b
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 #-}
ignored :: IxTraversal i s s a b
ignored :: IxTraversal i s s a b
ignored = IxTraversalVL i s s a b -> IxTraversal i s s a b
forall i s t a b. IxTraversalVL i s t a b -> IxTraversal i s t a b
itraversalVL (IxTraversalVL i s s a b -> IxTraversal i s s a b)
-> IxTraversalVL i s s a b -> IxTraversal i s s a b
forall a b. (a -> b) -> a -> b
$ \_ -> s -> f s
forall (f :: * -> *) a. Applicative f => a -> f a
pure
indices
:: (Is k A_Traversal, is `HasSingleIndex` i)
=> (i -> Bool)
-> Optic k is s t a a
-> IxTraversal i s t a a
indices :: (i -> Bool) -> Optic k is s t a a -> IxTraversal i s t a a
indices p :: i -> Bool
p o :: Optic k is s t a a
o = IxTraversalVL i s t a a -> IxTraversal i s t a a
forall i s t a b. IxTraversalVL i s t a b -> IxTraversal i s t a b
itraversalVL (IxTraversalVL i s t a a -> IxTraversal i s t a a)
-> IxTraversalVL i s t a a -> IxTraversal i s t a a
forall a b. (a -> b) -> a -> b
$ \f :: i -> a -> f a
f ->
Optic k is s t a a -> (i -> a -> f a) -> s -> f 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 a
o ((i -> a -> f a) -> s -> f t) -> (i -> a -> f a) -> s -> f t
forall a b. (a -> b) -> a -> b
$ \i :: i
i a :: a
a -> if i -> Bool
p i
i then i -> a -> f a
f i
i a
a else a -> f a
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 :: Optic k is s t a b -> IxTraversal i s t a b
ibackwards o :: Optic k is s t a b
o = Optic A_Traversal NoIx s t a b
-> IxTraversal i s t a b -> IxTraversal i s t a b
forall (is :: IxList) i k s t a b.
HasSingleIndex is i =>
Optic k NoIx s t a b -> Optic k is s t a b -> Optic k is s t a b
conjoined (Optic k is s t a b -> Optic A_Traversal NoIx s t a b
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) (IxTraversal i s t a b -> IxTraversal i s t a b)
-> IxTraversal i s t a b -> IxTraversal i s t a b
forall a b. (a -> b) -> a -> b
$ IxTraversalVL i s t a b -> IxTraversal i s t a b
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 -> IxTraversal i s t a b)
-> IxTraversalVL i s t a b -> IxTraversal i s t a b
forall a b. (a -> b) -> a -> b
$ \f :: i -> a -> f b
f ->
Backwards f t -> f t
forall k (f :: k -> *) (a :: k). Backwards f a -> f a
forwards (Backwards f t -> f t) -> (s -> Backwards f t) -> s -> f t
forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. Optic k is s t a b
-> (i -> a -> Backwards f b) -> s -> Backwards f 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
i -> f b -> Backwards f b
forall k (f :: k -> *) (a :: k). f a -> Backwards f a
Backwards (f b -> Backwards f b) -> (a -> f b) -> a -> Backwards f b
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 :: Optic k is s t a a -> (Int -> Bool) -> IxTraversal Int s t a a
elementsOf o :: Optic k is s t a a
o = \p :: Int -> Bool
p -> IxTraversalVL Int s t a a -> IxTraversal Int s t a a
forall i s t a b. IxTraversalVL i s t a b -> IxTraversal i s t a b
itraversalVL (IxTraversalVL Int s t a a -> IxTraversal Int s t a a)
-> IxTraversalVL Int s t a a -> IxTraversal Int s t a a
forall a b. (a -> b) -> a -> b
$ \f :: Int -> a -> f a
f ->
((a -> Indexing f a) -> s -> Indexing f t)
-> (Int -> a -> f a) -> s -> f t
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 (Optic k is s t a a -> (a -> Indexing f a) -> s -> Indexing 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 k is s t a a
o) ((Int -> a -> f a) -> s -> f t) -> (Int -> a -> f a) -> s -> f t
forall a b. (a -> b) -> a -> b
$ \i :: Int
i a :: a
a -> if Int -> Bool
p Int
i then Int -> a -> f a
f Int
i a
a else a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a
{-# INLINE elementsOf #-}
elements :: Traversable f => (Int -> Bool) -> IxTraversal' Int (f a) a
elements :: (Int -> Bool) -> IxTraversal' Int (f a) a
elements = Optic A_Traversal NoIx (f a) (f a) a a
-> (Int -> Bool) -> IxTraversal' Int (f a) a
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 A_Traversal NoIx (f a) (f a) a a
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 t a a
-> Int
-> IxTraversal Int s t a a
elementOf :: Optic k is s t a a -> Int -> IxTraversal Int s t a a
elementOf o :: Optic k is s t a a
o = \i :: Int
i -> Optic k is s t a a -> (Int -> Bool) -> IxTraversal Int s t a a
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 -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
i)
{-# INLINE elementOf #-}
element :: Traversable f => Int -> IxTraversal' Int (f a) a
element :: Int -> IxTraversal' Int (f a) a
element = Optic A_Traversal NoIx (f a) (f a) a a
-> Int -> IxTraversal' Int (f a) a
forall k (is :: IxList) s t a.
Is k A_Traversal =>
Optic k is s t a a -> Int -> IxTraversal Int s t a a
elementOf Optic A_Traversal NoIx (f a) (f a) a a
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 :: Optic k is s t a a -> IxLens [i] s t [a] [a]
ipartsOf o :: Optic k is s t a a
o = Optic A_Lens NoIx s t [a] [a]
-> IxLens [i] s t [a] [a] -> IxLens [i] s t [a] [a]
forall (is :: IxList) i k s t a b.
HasSingleIndex is i =>
Optic k NoIx s t a b -> Optic k is s t a b -> Optic k is s t a b
conjoined (Optic k is s t a a -> Optic A_Lens NoIx s t [a] [a]
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) (IxLens [i] s t [a] [a] -> IxLens [i] s t [a] [a])
-> IxLens [i] s t [a] [a] -> IxLens [i] s t [a] [a]
forall a b. (a -> b) -> a -> b
$ IxLensVL [i] s t [a] [a] -> IxLens [i] s t [a] [a]
forall i s t a b. IxLensVL i s t a b -> IxLens i s t a b
ilensVL (IxLensVL [i] s t [a] [a] -> IxLens [i] s t [a] [a])
-> IxLensVL [i] s t [a] [a] -> IxLens [i] s t [a] [a]
forall a b. (a -> b) -> a -> b
$ \f :: [i] -> [a] -> f [a]
f s :: s
s ->
State [a] t -> [a] -> t
forall s a. State s a -> s -> a
evalState (Optic k is s t a a
-> (a -> StateT [a] Identity a) -> s -> State [a] 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 k is s t a a
o a -> StateT [a] Identity a
forall (m :: * -> *) b. Monad m => b -> StateT [b] m b
update s
s)
([a] -> t) -> f [a] -> f t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([i] -> [a] -> f [a]) -> ([i], [a]) -> f [a]
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry [i] -> [a] -> f [a]
f ([(i, a)] -> ([i], [a])
forall a b. [(a, b)] -> ([a], [b])
unzip ([(i, a)] -> ([i], [a])) -> [(i, a)] -> ([i], [a])
forall a b. (a -> b) -> a -> b
$ Optic' A_Fold is s a -> s -> [(i, a)]
forall k (is :: IxList) i s a.
(Is k A_Fold, HasSingleIndex is i) =>
Optic' k is s a -> s -> [(i, a)]
itoListOf (Optic A_Traversal is s t a a -> Optic' A_Fold is s a
forall k s t a b (is :: IxList).
ToReadOnly k s t a b =>
Optic k is s t a b -> Optic' (Join A_Getter k) is s a
getting (Optic A_Traversal is s t a a -> Optic' A_Fold is s a)
-> Optic A_Traversal is s t a a -> Optic' A_Fold is s a
forall a b. (a -> b) -> a -> b
$ Optic k is s t a a -> Optic A_Traversal is s t a a
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 a :: b
a = StateT [b] m [b]
forall (m :: * -> *) s. Monad m => StateT s m s
get StateT [b] m [b] -> ([b] -> StateT [b] m b) -> StateT [b] m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
[] -> b -> StateT [b] m b
forall (f :: * -> *) a. Applicative f => a -> f a
pure b
a
a' :: b
a' : as' :: [b]
as' -> [b] -> StateT [b] m ()
forall (m :: * -> *) s. Monad m => s -> StateT s m ()
put [b]
as' StateT [b] m () -> StateT [b] m b -> StateT [b] m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> b -> StateT [b] m b
forall (f :: * -> *) a. Applicative f => a -> f a
pure b
a'
{-# INLINE ipartsOf #-}