packages feed

either-n-0.1.0.0: src/Data/Lens/Injection/Injection18.hs

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# OPTIONS_GHC -Wall #-}

-- | The eighteenth injection of a sum type, as a prism. The sum-type dual of 'Control.Lens.Field18'.
module Data.Lens.Injection.Injection18 (
  Injection18 (..),
) 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 eighteenth constructor of a sum type.

Where 'Control.Lens._18' is the eighteenth projection out of a product, '_I18' is the eighteenth
injection into a sum.

The default implementation is the prism to the eighteenth constructor of a
'Generic' type, @'injection' (Proxy :: Proxy 17)@.

>>> data T = C1 | C2 | C3 | C4 | C5 | C6 | C7 | C8 | C9 | C10 | C11 | C12 | C13 | C14 | C15 | C16 | C17 | C18 Int | C19 deriving (Show, Generic)
>>> instance Injection18 T T Int Int
>>> C18 1 ^? _I18
Just 1

>>> C19 ^? _I18
Nothing

>>> _I18 # 1 :: T
C18 1
-}
class Injection18 s t a b | s -> a, t -> b, s b -> t, t a -> s where
  _I18 :: Prism s t a b
  default _I18 :: (Generic s, Generic t, GInjection 17 (Rep s) (Rep t) a b) => Prism s t a b
  _I18 =
    injection (Proxy :: Proxy 17)
  {-# INLINE _I18 #-}