packages feed

document-build-0.2.0.0: src/Document/Build/Error/InputFilesTooFew.hs

{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wall #-}

{- | A directory that has fewer input files than a command needs.

A 'InputFilesTooFew' is a product: its fields are named 'directory', 'inputFileCount' and 'inputFilesNeeded'.
-}
module Document.Build.Error.InputFilesTooFew (
  -- * Type
  InputFilesTooFew (..),

  -- * Optics
  InputFilesTooFewLike (..),
  lawNamesInputFilesTooFew,
  InheritInputFilesTooFew,
  inheritInputFilesTooFew,
) where

import Control.DeepSeq (NFData)
import Control.Lens (Optic, cloneLens, view)
import Data.Data (Data)
import Data.Functor.Const (Const)
import Document.Build.Name.Directory (DirectoryLike (..))
import Document.Build.Name.InputFileCount (InputFileCountLike (..))
import Document.Build.Name.InputFilesNeeded (InputFilesNeededLike (..))
import GHC.Generics (Generic)

{- | A directory ('directory') has fewer input files ('inputFileCount') than a command
needs ('inputFilesNeeded').

@since 0.2.0.0
-}
data InputFilesTooFew
  = InputFilesTooFew FilePath Int Int
  deriving stock (Eq, Ord, Show, Generic, Data)
  deriving anyclass (NFData)

{- | The class of 'InputFilesTooFew'.

@since 0.2.0.0
-}
class InputFilesTooFewLike p f x x' where
  inputFilesTooFew ::
    Optic p f x x' InputFilesTooFew InputFilesTooFew

{- | Identity

@since 0.2.0.0
-}
instance (x' ~ InputFilesTooFew) => InputFilesTooFewLike p f InputFilesTooFew x' where
  inputFilesTooFew =
    id
  {-# INLINE inputFilesTooFew #-}

{- | Lens

@since 0.2.0.0
-}
instance (p ~ (->), Functor f, x' ~ InputFilesTooFew) => DirectoryLike p f InputFilesTooFew x' where
  directory f (InputFilesTooFew x1 x2 x3) =
    fmap (\x1' -> InputFilesTooFew x1' x2 x3) (f x1)
  {-# INLINE directory #-}

{- | Lens

@since 0.2.0.0
-}
instance (p ~ (->), Functor f, x' ~ InputFilesTooFew) => InputFileCountLike p f InputFilesTooFew x' where
  inputFileCount f (InputFilesTooFew x1 x2 x3) =
    fmap (\x2' -> InputFilesTooFew x1 x2' x3) (f x2)
  {-# INLINE inputFileCount #-}

{- | Lens

@since 0.2.0.0
-}
instance (p ~ (->), Functor f, x' ~ InputFilesTooFew) => InputFilesNeededLike p f InputFilesTooFew x' where
  inputFilesNeeded f (InputFilesTooFew x1 x2 x3) =
    fmap (InputFilesTooFew x1 x2) (f x3)
  {-# INLINE inputFilesNeeded #-}

{- | Rebuild a value using only the name of each field.

Laws:

> lawNamesInputFilesTooFew == id

@since 0.2.0.0
-}
lawNamesInputFilesTooFew :: InputFilesTooFew -> InputFilesTooFew
lawNamesInputFilesTooFew s =
  InputFilesTooFew
    (view (cloneLens directory) s)
    (view (cloneLens inputFileCount) s)
    (view (cloneLens inputFilesNeeded) s)

{- | The classes that a data type holding 'InputFilesTooFew' inherits.

@since 0.2.0.0
-}
type InheritInputFilesTooFew s =
  ( InputFilesTooFewLike (->) (Const ()) s s
  , DirectoryLike (->) (Const ()) s s
  , InputFileCountLike (->) (Const ()) s s
  , InputFilesNeededLike (->) (Const ()) s s
  )

{- | Check, where it is applied, that @s@ inherits every name of 'InputFilesTooFew'.

@since 0.2.0.0
-}
inheritInputFilesTooFew :: (InheritInputFilesTooFew s) => proxy s -> ()
inheritInputFilesTooFew _ =
  ()