{-# LANGUAGE PackageImports #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module Data.Generics.Sum.Typed
(
AsType (..)
) where
import "this" Data.Generics.Internal.Optics
import qualified "generic-lens-core" Data.Generics.Sum.Internal.Typed as Core
import "generic-lens-core" Data.Generics.Internal.Void
class AsType a s where
_Typed :: Prism' s a
_Typed = (a -> s) -> (s -> Either s a) -> Prism' s a
forall b t s a. (b -> t) -> (s -> Either t a) -> Prism s t a b
prism a -> s
forall a s. AsType a s => a -> s
injectTyped (\s
i -> Either s a -> (a -> Either s a) -> Maybe a -> Either s a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (s -> Either s a
forall a b. a -> Either a b
Left s
i) a -> Either s a
forall a b. b -> Either a b
Right (s -> Maybe a
forall a s. AsType a s => s -> Maybe a
projectTyped s
i))
{-# INLINE _Typed #-}
injectTyped :: a -> s
injectTyped
= Prism' s a -> a -> s
forall k (is :: IxList) t b.
Is k A_Review =>
Optic' k is t b -> b -> t
review Prism' s a
forall a s. AsType a s => Prism' s a
_Typed
projectTyped :: s -> Maybe a
projectTyped
= (s -> Maybe a) -> (a -> Maybe a) -> Either s a -> Maybe a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Maybe a -> s -> Maybe a
forall a b. a -> b -> a
const Maybe a
forall a. Maybe a
Nothing) a -> Maybe a
forall a. a -> Maybe a
Just (Either s a -> Maybe a) -> (s -> Either s a) -> s -> Maybe a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Prism' s a -> s -> Either s a
forall k (is :: IxList) s t a b.
Is k An_AffineTraversal =>
Optic k is s t a b -> s -> Either t a
matching Prism' s a
forall a s. AsType a s => Prism' s a
_Typed
{-# MINIMAL (injectTyped, projectTyped) | _Typed #-}
instance Core.Context a s => AsType a s where
_Typed :: Prism' s a
_Typed = Prism' s a -> Prism' s a
forall s t a b. Prism s t a b -> Prism s t a b
normalisePrism ((forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ A_Prism p i (Curry NoIx i) s s a a)
-> Prism' s a
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 a s. Context a s => Prism' s a
forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ A_Prism p i (Curry NoIx i) s s a a
Core.derived)
{-# INLINE _Typed #-}
instance {-# OVERLAPPING #-} AsType a Void where
_Typed :: Prism' Void a
_Typed = Prism' Void a
forall a. HasCallStack => a
undefined
injectTyped :: a -> Void
injectTyped = a -> Void
forall a. HasCallStack => a
undefined
projectTyped :: Void -> Maybe a
projectTyped = Void -> Maybe a
forall a. HasCallStack => a
undefined
instance {-# OVERLAPPING #-} AsType Void a where
_Typed :: Prism' a Void
_Typed = Prism' a Void
forall a. HasCallStack => a
undefined
injectTyped :: Void -> a
injectTyped = Void -> a
forall a. HasCallStack => a
undefined
projectTyped :: a -> Maybe Void
projectTyped = a -> Maybe Void
forall a. HasCallStack => a
undefined