module Optics.AffineTraversal
(
AffineTraversal
, AffineTraversal'
, atraversal
, matching
, unsafeFiltered
, withAffineTraversal
, An_AffineTraversal
, AffineTraversalVL
, AffineTraversalVL'
, atraversalVL
, atraverseOf
)
where
import Data.Profunctor.Indexed
import Optics.Internal.Optic
type AffineTraversal s t a b = Optic An_AffineTraversal NoIx s t a b
type AffineTraversal' s a = Optic' An_AffineTraversal NoIx s a
type AffineTraversalVL s t a b =
forall f. Functor f => (forall r. r -> f r) -> (a -> f b) -> s -> f t
type AffineTraversalVL' s a = AffineTraversalVL s s a a
atraversal :: (s -> Either t a) -> (s -> b -> t) -> AffineTraversal s t a b
atraversal :: (s -> Either t a) -> (s -> b -> t) -> AffineTraversal s t a b
atraversal s -> Either t a
match s -> b -> t
update = (forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ An_AffineTraversal p i (Curry NoIx i) s t a b)
-> AffineTraversal 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 ((forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ An_AffineTraversal p i (Curry NoIx i) s t a b)
-> AffineTraversal s t a b)
-> (forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ An_AffineTraversal p i (Curry NoIx i) s t a b)
-> AffineTraversal s t a b
forall a b. (a -> b) -> a -> b
$
(s -> (Either t a, b -> t))
-> ((Either t b, b -> t) -> t)
-> p i (Either t a, b -> t) (Either t b, b -> t)
-> p i s t
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 -> Either t a
match s
s, s -> b -> t
update s
s))
(\(Either t b
etb, b -> t
f) -> (t -> t) -> (b -> t) -> Either t b -> t
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either t -> t
forall a. a -> a
id b -> t
f Either t b
etb)
(p i (Either t a, b -> t) (Either t b, b -> t) -> p i s t)
-> (p i a b -> p i (Either t a, b -> t) (Either t b, b -> t))
-> p i a b
-> p i s t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p i (Either t a) (Either t b)
-> p i (Either t a, b -> t) (Either t b, b -> t)
forall (p :: * -> * -> * -> *) i a b c.
Strong p =>
p i a b -> p i (a, c) (b, c)
first'
(p i (Either t a) (Either t b)
-> p i (Either t a, b -> t) (Either t b, b -> t))
-> (p i a b -> p i (Either t a) (Either t b))
-> p i a b
-> p i (Either t a, b -> t) (Either t b, b -> t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p i a b -> p i (Either t a) (Either t b)
forall (p :: * -> * -> * -> *) i a b c.
Choice p =>
p i a b -> p i (Either c a) (Either c b)
right'
{-# INLINE atraversal #-}
withAffineTraversal
:: Is k An_AffineTraversal
=> Optic k is s t a b
-> ((s -> Either t a) -> (s -> b -> t) -> r)
-> r
withAffineTraversal :: Optic k is s t a b
-> ((s -> Either t a) -> (s -> b -> t) -> r) -> r
withAffineTraversal Optic k is s t a b
o = \(s -> Either t a) -> (s -> b -> t) -> r
k ->
case Optic An_AffineTraversal is s t a b
-> Optic__ (AffineMarket a b) Any (Curry is Any) s t a b
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 (Optic k is s t a b -> Optic An_AffineTraversal 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 @An_AffineTraversal Optic k is s t a b
o) ((a -> b -> b) -> (a -> Either b a) -> AffineMarket a b Any a b
forall a b i s t.
(s -> b -> t) -> (s -> Either t a) -> AffineMarket a b i s t
AffineMarket (\a
_ b
b -> b
b) a -> Either b a
forall a b. b -> Either a b
Right) of
AffineMarket update match -> (s -> Either t a) -> (s -> b -> t) -> r
k s -> Either t a
match s -> b -> t
update
{-# INLINE withAffineTraversal #-}
atraversalVL :: AffineTraversalVL s t a b -> AffineTraversal s t a b
atraversalVL :: AffineTraversalVL s t a b -> AffineTraversal s t a b
atraversalVL AffineTraversalVL s t a b
f = (forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ An_AffineTraversal p i (Curry NoIx i) s t a b)
-> AffineTraversal 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 (AffineTraversalVL s t a b -> p i a b -> p i s t
forall (p :: * -> * -> * -> *) i s t a b.
Visiting p =>
(forall (f :: * -> *).
Functor f =>
(forall r. r -> f r) -> (a -> f b) -> s -> f t)
-> p i a b -> p i s t
visit AffineTraversalVL s t a b
f)
{-# INLINE atraversalVL #-}
atraverseOf
:: (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 k is s t a b
-> (forall r. r -> f r) -> (a -> f b) -> s -> f t
atraverseOf Optic k is s t a b
o forall r. r -> f r
point =
StarA f (Curry is Any) s t -> s -> f t
forall (f :: * -> *) i a b. StarA f i a b -> a -> f b
runStarA (StarA f (Curry is Any) s t -> s -> f t)
-> ((a -> f b) -> StarA f (Curry is Any) s t)
-> (a -> f b)
-> s
-> f t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Optic An_AffineTraversal is s t a b
-> Optic_ An_AffineTraversal (StarA f) Any (Curry is Any) s t a b
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 (Optic k is s t a b -> Optic An_AffineTraversal 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 @An_AffineTraversal Optic k is s t a b
o) Optic__ (StarA f) Any (Curry is Any) s t a b
-> ((a -> f b) -> StarA f Any a b)
-> (a -> f b)
-> StarA f (Curry is Any) s t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall r. r -> f r) -> (a -> f b) -> StarA f Any a b
forall (f :: * -> *) i a b.
(forall r. r -> f r) -> (a -> f b) -> StarA f i a b
StarA forall r. r -> f r
point
{-# INLINE atraverseOf #-}
matching :: Is k An_AffineTraversal => Optic k is s t a b -> s -> Either t a
matching :: Optic k is s t a b -> s -> Either t a
matching Optic k is s t a b
o = Optic k is s t a b
-> ((s -> Either t a) -> (s -> b -> t) -> s -> Either t a)
-> s
-> Either t a
forall k (is :: IxList) s t a b r.
Is k An_AffineTraversal =>
Optic k is s t a b
-> ((s -> Either t a) -> (s -> b -> t) -> r) -> r
withAffineTraversal Optic k is s t a b
o (((s -> Either t a) -> (s -> b -> t) -> s -> Either t a)
-> s -> Either t a)
-> ((s -> Either t a) -> (s -> b -> t) -> s -> Either t a)
-> s
-> Either t a
forall a b. (a -> b) -> a -> b
$ \s -> Either t a
match s -> b -> t
_ -> s -> Either t a
match
{-# INLINE matching #-}
unsafeFiltered :: (a -> Bool) -> AffineTraversal' a a
unsafeFiltered :: (a -> Bool) -> AffineTraversal' a a
unsafeFiltered a -> Bool
p = AffineTraversalVL a a a a -> AffineTraversal' a a
forall s t a b.
AffineTraversalVL s t a b -> AffineTraversal s t a b
atraversalVL (\forall r. r -> f r
point a -> f a
f a
a -> if a -> Bool
p a
a then a -> f a
f a
a else a -> f a
forall r. r -> f r
point a
a)
{-# INLINE unsafeFiltered #-}