module LawfulConversions.Optics where
import Data.Profunctor
import LawfulConversions.Classes
import LawfulConversions.Prelude
isSomePrism :: (IsSome a b, Choice p, Applicative f) => p b (f b) -> p a (f a)
isSomePrism :: forall a b (p :: * -> * -> *) (f :: * -> *).
(IsSome a b, Choice p, Applicative f) =>
p b (f b) -> p a (f a)
isSomePrism =
(a -> Either a b)
-> (Either a (f b) -> f a)
-> p (Either a b) (Either a (f b))
-> p a (f a)
forall a b c d. (a -> b) -> (c -> d) -> p b c -> p a d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap
(\a
s -> Either a b -> (b -> Either a b) -> Maybe b -> Either a b
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (a -> Either a b
forall a b. a -> Either a b
Left a
s) b -> Either a b
forall a b. b -> Either a b
Right (a -> Maybe b
forall a b. IsSome a b => a -> Maybe b
maybeFrom a
s))
((a -> f a) -> (f b -> f a) -> Either a (f b) -> f a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either a -> f a
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ((b -> a) -> f b -> f a
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> a
forall a b. IsSome a b => b -> a
to))
(p (Either a b) (Either a (f b)) -> p a (f a))
-> (p b (f b) -> p (Either a b) (Either a (f b)))
-> p b (f b)
-> p a (f a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. p b (f b) -> p (Either a b) (Either a (f b))
forall a b c. p a b -> p (Either c a) (Either c b)
forall (p :: * -> * -> *) a b c.
Choice p =>
p a b -> p (Either c a) (Either c b)
right'
isManyIso :: (IsMany a b, Profunctor p, Functor f) => p b (f b) -> p a (f a)
isManyIso :: forall a b (p :: * -> * -> *) (f :: * -> *).
(IsMany a b, Profunctor p, Functor f) =>
p b (f b) -> p a (f a)
isManyIso = (a -> b) -> (f b -> f a) -> p b (f b) -> p a (f a)
forall a b c d. (a -> b) -> (c -> d) -> p b c -> p a d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap a -> b
forall a b. IsMany a b => a -> b
from ((b -> a) -> f b -> f a
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> a
forall a b. IsSome a b => b -> a
to)
isIso :: (Is a b, Profunctor p, Functor f) => p b (f b) -> p a (f a)
isIso :: forall a b (p :: * -> * -> *) (f :: * -> *).
(Is a b, Profunctor p, Functor f) =>
p b (f b) -> p a (f a)
isIso = p b (f b) -> p a (f a)
forall a b (p :: * -> * -> *) (f :: * -> *).
(IsMany a b, Profunctor p, Functor f) =>
p b (f b) -> p a (f a)
isManyIso