module Optics.IxAffineTraversal
(
IxAffineTraversal
, IxAffineTraversal'
, iatraversal
, unsafeFilteredBy
, ignored
, An_AffineTraversal
, IxAffineTraversalVL
, IxAffineTraversalVL'
, iatraversalVL
, iatraverseOf
) where
import Data.Profunctor.Indexed
import Optics.AffineFold
import Optics.Internal.Indexed
import Optics.Internal.Optic
import Optics.Internal.Utils
type IxAffineTraversal i s t a b = Optic An_AffineTraversal (WithIx i) s t a b
type IxAffineTraversal' i s a = Optic' An_AffineTraversal (WithIx i) s a
type IxAffineTraversalVL i s t a b =
forall f. Functor f => (forall r. r -> f r) -> (i -> a -> f b) -> s -> f t
type IxAffineTraversalVL' i s a = IxAffineTraversalVL i s s a a
iatraversal :: (s -> Either t (i, a)) -> (s -> b -> t) -> IxAffineTraversal i s t a b
iatraversal :: forall s t i a b.
(s -> Either t (i, a))
-> (s -> b -> t) -> IxAffineTraversal i s t a b
iatraversal s -> Either t (i, a)
match s -> b -> t
update = 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 b
f s
s ->
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall r. r -> f r
point (\(i, a)
a -> s -> b -> t
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 b
f (i, a)
a) (s -> Either t (i, a)
match s
s)
{-# INLINE iatraversal #-}
iatraversalVL :: IxAffineTraversalVL i s t a b -> IxAffineTraversal i s t a b
iatraversalVL :: forall i s t a b.
IxAffineTraversalVL i s t a b -> IxAffineTraversal i s t a b
iatraversalVL IxAffineTraversalVL i s t a b
f = 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.
Visiting p =>
(forall (f :: * -> *).
Functor f =>
(forall r. r -> f r) -> (i -> a -> f b) -> s -> f t)
-> p j a b -> p (i -> j) s t
ivisit IxAffineTraversalVL i s t a b
f)
{-# INLINE iatraversalVL #-}
iatraverseOf
:: (Is k An_AffineTraversal, Functor f, is `HasSingleIndex` i)
=> Optic k is s t a b
-> (forall r. r -> f r) -> (i -> a -> f b) -> s -> f t
iatraverseOf :: forall k (f :: * -> *) (is :: IxList) i s t a b.
(Is k An_AffineTraversal, Functor f, HasSingleIndex is i) =>
Optic k is s t a b
-> (forall r. r -> f r) -> (i -> a -> f b) -> s -> f t
iatraverseOf Optic k is s t a b
o forall r. r -> f r
point = \i -> a -> f b
f ->
forall (f :: * -> *) i a b. IxStarA f i a b -> i -> a -> f b
runIxStarA (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 @An_AffineTraversal Optic k is s t a b
o) (forall (f :: * -> *) i a b.
(forall r. r -> f r) -> (i -> a -> f b) -> IxStarA f i a b
IxStarA forall r. r -> f r
point i -> a -> f b
f)) forall a. a -> a
id
{-# INLINE iatraverseOf #-}
unsafeFilteredBy
:: Is k An_AffineFold
=> Optic' k is a i
-> IxAffineTraversal' i a a
unsafeFilteredBy :: forall k (is :: IxList) a i.
Is k An_AffineFold =>
Optic' k is a i -> IxAffineTraversal' i a a
unsafeFilteredBy Optic' k is a i
p = 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 a
s -> case forall k (is :: IxList) s a.
Is k An_AffineFold =>
Optic' k is s a -> s -> Maybe a
preview Optic' k is a i
p a
s of
Just i
i -> i -> a -> f a
f i
i a
s
Maybe i
Nothing -> forall r. r -> f r
point a
s
{-# INLINE unsafeFilteredBy #-}
ignored :: IxAffineTraversal i s s a b
ignored :: forall i s a b. IxAffineTraversal i s s a b
ignored = 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 b
_ -> forall r. r -> f r
point
{-# INLINE ignored #-}