{-# LANGUAGE CPP #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE RankNTypes #-}
{-# OPTIONS_GHC -Wno-warnings-deprecations #-}
module Control.Lens.Unsound
(
lensProduct
, prismSum
, adjoin
) where
import Control.Lens
import Control.Lens.Internal.Prelude
import Prelude ()
lensProduct :: ALens' s a -> ALens' s b -> Lens' s (a, b)
lensProduct :: forall s a b. ALens' s a -> ALens' s b -> Lens' s (a, b)
lensProduct ALens' s a
l1 ALens' s b
l2 (a, b) -> f (a, b)
f s
s =
(a, b) -> f (a, b)
f (s
s s -> ALens' s a -> a
forall s t a b. s -> ALens s t a b -> a
^# ALens' s a
l1, s
s s -> ALens' s b -> b
forall s t a b. s -> ALens s t a b -> a
^# ALens' s b
l2) f (a, b) -> ((a, b) -> s) -> f s
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(a
a, b
b) -> s
s s -> (s -> s) -> s
forall a b. a -> (a -> b) -> b
& ALens' s a
l1 ALens' s a -> a -> s -> s
forall s t a b. ALens s t a b -> b -> s -> t
#~ a
a s -> (s -> s) -> s
forall a b. a -> (a -> b) -> b
& ALens' s b
l2 ALens' s b -> b -> s -> s
forall s t a b. ALens s t a b -> b -> s -> t
#~ b
b
prismSum :: APrism s t a b
-> APrism s t c d
-> Prism s t (Either a c) (Either b d)
prismSum :: forall s t a b c d.
APrism s t a b
-> APrism s t c d -> Prism s t (Either a c) (Either b d)
prismSum APrism s t a b
k APrism s t c d
k' =
APrism s t a b
-> ((b -> t)
-> (s -> Either t a)
-> p (Either a c) (f (Either b d))
-> p s (f t))
-> p (Either a c) (f (Either b d))
-> p s (f t)
forall s t a b r.
APrism s t a b -> ((b -> t) -> (s -> Either t a) -> r) -> r
withPrism APrism s t a b
k (((b -> t)
-> (s -> Either t a)
-> p (Either a c) (f (Either b d))
-> p s (f t))
-> p (Either a c) (f (Either b d)) -> p s (f t))
-> ((b -> t)
-> (s -> Either t a)
-> p (Either a c) (f (Either b d))
-> p s (f t))
-> p (Either a c) (f (Either b d))
-> p s (f t)
forall a b. (a -> b) -> a -> b
$ \b -> t
bt s -> Either t a
seta ->
APrism s t c d
-> ((d -> t)
-> (s -> Either t c)
-> p (Either a c) (f (Either b d))
-> p s (f t))
-> p (Either a c) (f (Either b d))
-> p s (f t)
forall s t a b r.
APrism s t a b -> ((b -> t) -> (s -> Either t a) -> r) -> r
withPrism APrism s t c d
k' (((d -> t)
-> (s -> Either t c)
-> p (Either a c) (f (Either b d))
-> p s (f t))
-> p (Either a c) (f (Either b d)) -> p s (f t))
-> ((d -> t)
-> (s -> Either t c)
-> p (Either a c) (f (Either b d))
-> p s (f t))
-> p (Either a c) (f (Either b d))
-> p s (f t)
forall a b. (a -> b) -> a -> b
$ \d -> t
dt s -> Either t c
setb ->
(Either b d -> t)
-> (s -> Either t (Either a c))
-> forall {p :: * -> * -> *} {f :: * -> *}.
(Choice p, Applicative f) =>
p (Either a c) (f (Either b d)) -> p s (f t)
forall b t s a. (b -> t) -> (s -> Either t a) -> Prism s t a b
prism ((b -> t) -> (d -> t) -> Either b d -> t
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either b -> t
bt d -> t
dt) ((s -> Either t (Either a c))
-> forall {p :: * -> * -> *} {f :: * -> *}.
(Choice p, Applicative f) =>
p (Either a c) (f (Either b d)) -> p s (f t))
-> (s -> Either t (Either a c))
-> forall {p :: * -> * -> *} {f :: * -> *}.
(Choice p, Applicative f) =>
p (Either a c) (f (Either b d)) -> p s (f t)
forall a b. (a -> b) -> a -> b
$ \s
s ->
Either t (Either a c)
-> Either t (Either a c) -> Either t (Either a c)
forall {a} {b}. Either a b -> Either a b -> Either a b
f (a -> Either a c
forall a b. a -> Either a b
Left (a -> Either a c) -> Either t a -> Either t (Either a c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Either t a
seta s
s) (c -> Either a c
forall a b. b -> Either a b
Right (c -> Either a c) -> Either t c -> Either t (Either a c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> Either t c
setb s
s)
where
f :: Either a b -> Either a b -> Either a b
f a :: Either a b
a@(Right b
_) Either a b
_ = Either a b
a
f (Left a
_) Either a b
b = Either a b
b
adjoin :: Traversal' s a -> Traversal' s a -> Traversal' s a
adjoin :: forall s a. Traversal' s a -> Traversal' s a -> Traversal' s a
adjoin Traversal' s a
t1 Traversal' s a
t2 =
ALens' s [a] -> ALens' s [a] -> Lens' s ([a], [a])
forall s a b. ALens' s a -> ALens' s b -> Lens' s (a, b)
lensProduct (Traversing (->) (Pretext (->) [a] [a]) s s a a -> ALens' s [a]
forall (f :: * -> *) s t a.
Functor f =>
Traversing (->) f s t a a -> LensLike f s t [a] [a]
partsOf Traversing (->) (Pretext (->) [a] [a]) s s a a
Traversal' s a
t1) (Traversing (->) (Pretext (->) [a] [a]) s s a a -> ALens' s [a]
forall (f :: * -> *) s t a.
Functor f =>
Traversing (->) f s t a a -> LensLike f s t [a] [a]
partsOf Traversing (->) (Pretext (->) [a] [a]) s s a a
Traversal' s a
t2) ((([a], [a]) -> f ([a], [a])) -> s -> f s)
-> ((a -> f a) -> ([a], [a]) -> f ([a], [a]))
-> (a -> f a)
-> s
-> f s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([a] -> f [a]) -> ([a], [a]) -> f ([a], [a])
Traversal ([a], [a]) ([a], [a]) [a] [a]
forall (r :: * -> * -> *) a b.
Bitraversable r =>
Traversal (r a a) (r b b) a b
both (([a] -> f [a]) -> ([a], [a]) -> f ([a], [a]))
-> ((a -> f a) -> [a] -> f [a])
-> (a -> f a)
-> ([a], [a])
-> f ([a], [a])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> f a) -> [a] -> f [a]
forall s t a b. Each s t a b => Traversal s t a b
Traversal [a] [a] a a
each