either-n-0.1.0.0: src/Data/Lens/Injection/Injection7.hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# OPTIONS_GHC -Wall #-}
-- | The seventh injection of a sum type, as a prism. The sum-type dual of 'Control.Lens.Field7'.
module Data.Lens.Injection.Injection7 (
Injection7 (..),
) where
import Control.Lens (Prism)
import Data.Lens.Injection.Generic (GInjection, injection)
import Data.Proxy (Proxy (..))
import GHC.Generics (Generic, Rep)
{- $setup
>>> :set -XDeriveGeneric -XMultiParamTypeClasses -XFlexibleInstances
>>> import Control.Lens((^?), (#))
>>> import GHC.Generics(Generic)
-}
{- | Access the seventh constructor of a sum type.
Where 'Control.Lens._7' is the seventh projection out of a product, '_I7' is the seventh
injection into a sum.
The default implementation is the prism to the seventh constructor of a
'Generic' type, @'injection' (Proxy :: Proxy 6)@.
>>> data T = C1 | C2 | C3 | C4 | C5 | C6 | C7 Int | C8 deriving (Show, Generic)
>>> instance Injection7 T T Int Int
>>> C7 1 ^? _I7
Just 1
>>> C8 ^? _I7
Nothing
>>> _I7 # 1 :: T
C7 1
-}
class Injection7 s t a b | s -> a, t -> b, s b -> t, t a -> s where
_I7 :: Prism s t a b
default _I7 :: (Generic s, Generic t, GInjection 6 (Rep s) (Rep t) a b) => Prism s t a b
_I7 =
injection (Proxy :: Proxy 6)
{-# INLINE _I7 #-}