{-# LANGUAGE UndecidableInstances #-}
module PathSize.Data.Config
(
Config (..),
defaultConfig,
Strategy (..),
_Sync,
_Async,
_AsyncPool,
defaultNumPaths,
defaultNumPathsSize,
)
where
import Data.HashSet (HashSet)
import Data.HashSet qualified as HSet
import Data.Word (Word16)
import Effects.FileSystem.OsPath (OsPath)
import Numeric.Data.Positive.Internal (Positive (UnsafePositive))
import Optics.Core
( A_Lens,
LabelOptic (labelOptic),
Prism',
lensVL,
prism,
)
data Strategy
=
Sync
|
Async
|
AsyncPool
deriving stock
(
Strategy
Strategy -> Strategy -> Bounded Strategy
forall a. a -> a -> Bounded a
$cminBound :: Strategy
minBound :: Strategy
$cmaxBound :: Strategy
maxBound :: Strategy
Bounded,
Strategy -> Strategy -> Bool
(Strategy -> Strategy -> Bool)
-> (Strategy -> Strategy -> Bool) -> Eq Strategy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Strategy -> Strategy -> Bool
== :: Strategy -> Strategy -> Bool
$c/= :: Strategy -> Strategy -> Bool
/= :: Strategy -> Strategy -> Bool
Eq,
Int -> Strategy
Strategy -> Int
Strategy -> [Strategy]
Strategy -> Strategy
Strategy -> Strategy -> [Strategy]
Strategy -> Strategy -> Strategy -> [Strategy]
(Strategy -> Strategy)
-> (Strategy -> Strategy)
-> (Int -> Strategy)
-> (Strategy -> Int)
-> (Strategy -> [Strategy])
-> (Strategy -> Strategy -> [Strategy])
-> (Strategy -> Strategy -> [Strategy])
-> (Strategy -> Strategy -> Strategy -> [Strategy])
-> Enum Strategy
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: Strategy -> Strategy
succ :: Strategy -> Strategy
$cpred :: Strategy -> Strategy
pred :: Strategy -> Strategy
$ctoEnum :: Int -> Strategy
toEnum :: Int -> Strategy
$cfromEnum :: Strategy -> Int
fromEnum :: Strategy -> Int
$cenumFrom :: Strategy -> [Strategy]
enumFrom :: Strategy -> [Strategy]
$cenumFromThen :: Strategy -> Strategy -> [Strategy]
enumFromThen :: Strategy -> Strategy -> [Strategy]
$cenumFromTo :: Strategy -> Strategy -> [Strategy]
enumFromTo :: Strategy -> Strategy -> [Strategy]
$cenumFromThenTo :: Strategy -> Strategy -> Strategy -> [Strategy]
enumFromThenTo :: Strategy -> Strategy -> Strategy -> [Strategy]
Enum,
Eq Strategy
Eq Strategy =>
(Strategy -> Strategy -> Ordering)
-> (Strategy -> Strategy -> Bool)
-> (Strategy -> Strategy -> Bool)
-> (Strategy -> Strategy -> Bool)
-> (Strategy -> Strategy -> Bool)
-> (Strategy -> Strategy -> Strategy)
-> (Strategy -> Strategy -> Strategy)
-> Ord Strategy
Strategy -> Strategy -> Bool
Strategy -> Strategy -> Ordering
Strategy -> Strategy -> Strategy
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Strategy -> Strategy -> Ordering
compare :: Strategy -> Strategy -> Ordering
$c< :: Strategy -> Strategy -> Bool
< :: Strategy -> Strategy -> Bool
$c<= :: Strategy -> Strategy -> Bool
<= :: Strategy -> Strategy -> Bool
$c> :: Strategy -> Strategy -> Bool
> :: Strategy -> Strategy -> Bool
$c>= :: Strategy -> Strategy -> Bool
>= :: Strategy -> Strategy -> Bool
$cmax :: Strategy -> Strategy -> Strategy
max :: Strategy -> Strategy -> Strategy
$cmin :: Strategy -> Strategy -> Strategy
min :: Strategy -> Strategy -> Strategy
Ord,
Int -> Strategy -> ShowS
[Strategy] -> ShowS
Strategy -> [Char]
(Int -> Strategy -> ShowS)
-> (Strategy -> [Char]) -> ([Strategy] -> ShowS) -> Show Strategy
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Strategy -> ShowS
showsPrec :: Int -> Strategy -> ShowS
$cshow :: Strategy -> [Char]
show :: Strategy -> [Char]
$cshowList :: [Strategy] -> ShowS
showList :: [Strategy] -> ShowS
Show
)
_Sync :: Prism' Strategy ()
_Sync :: Prism' Strategy ()
_Sync =
(() -> Strategy)
-> (Strategy -> Either Strategy ()) -> Prism' Strategy ()
forall b t s a. (b -> t) -> (s -> Either t a) -> Prism s t a b
prism
(Strategy -> () -> Strategy
forall a b. a -> b -> a
const Strategy
Sync)
( \case
Strategy
Sync -> () -> Either Strategy ()
forall a b. b -> Either a b
Right ()
Strategy
x -> Strategy -> Either Strategy ()
forall a b. a -> Either a b
Left Strategy
x
)
{-# INLINE _Sync #-}
_Async :: Prism' Strategy ()
_Async :: Prism' Strategy ()
_Async =
(() -> Strategy)
-> (Strategy -> Either Strategy ()) -> Prism' Strategy ()
forall b t s a. (b -> t) -> (s -> Either t a) -> Prism s t a b
prism
(Strategy -> () -> Strategy
forall a b. a -> b -> a
const Strategy
Async)
( \case
Strategy
Async -> () -> Either Strategy ()
forall a b. b -> Either a b
Right ()
Strategy
x -> Strategy -> Either Strategy ()
forall a b. a -> Either a b
Left Strategy
x
)
{-# INLINE _Async #-}
_AsyncPool :: Prism' Strategy ()
_AsyncPool :: Prism' Strategy ()
_AsyncPool =
(() -> Strategy)
-> (Strategy -> Either Strategy ()) -> Prism' Strategy ()
forall b t s a. (b -> t) -> (s -> Either t a) -> Prism s t a b
prism
(Strategy -> () -> Strategy
forall a b. a -> b -> a
const Strategy
AsyncPool)
( \case
Strategy
AsyncPool -> () -> Either Strategy ()
forall a b. b -> Either a b
Right ()
Strategy
x -> Strategy -> Either Strategy ()
forall a b. a -> Either a b
Left Strategy
x
)
{-# INLINE _AsyncPool #-}
defaultNumPaths :: Positive Int
defaultNumPaths :: Positive Int
defaultNumPaths = Int -> Positive Int
forall a. a -> Positive a
UnsafePositive Int
10
defaultNumPathsSize :: Positive Int
defaultNumPathsSize :: Positive Int
defaultNumPathsSize = Int -> Positive Int
forall a. a -> Positive a
UnsafePositive Int
1
data Config = MkConfig
{
Config -> Bool
searchAll :: !Bool,
Config -> Maybe Word16
maxDepth :: !(Maybe Word16),
Config -> HashSet OsPath
exclude :: !(HashSet OsPath),
Config -> Bool
filesOnly :: !Bool,
Config -> Bool
ignoreDirIntrinsicSize :: !Bool,
Config -> Maybe (Positive Int)
numPaths :: !(Maybe (Positive Int)),
Config -> Bool
stableSort :: !Bool,
Config -> Strategy
strategy :: !Strategy
}
deriving stock
(
Config -> Config -> Bool
(Config -> Config -> Bool)
-> (Config -> Config -> Bool) -> Eq Config
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Config -> Config -> Bool
== :: Config -> Config -> Bool
$c/= :: Config -> Config -> Bool
/= :: Config -> Config -> Bool
Eq,
Int -> Config -> ShowS
[Config] -> ShowS
Config -> [Char]
(Int -> Config -> ShowS)
-> (Config -> [Char]) -> ([Config] -> ShowS) -> Show Config
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Config -> ShowS
showsPrec :: Int -> Config -> ShowS
$cshow :: Config -> [Char]
show :: Config -> [Char]
$cshowList :: [Config] -> ShowS
showList :: [Config] -> ShowS
Show
)
instance
(k ~ A_Lens, a ~ Bool, b ~ Bool) =>
LabelOptic "searchAll" k Config Config a b
where
labelOptic :: Optic k NoIx Config Config a b
labelOptic =
LensVL Config Config a b -> Lens Config Config a b
forall s t a b. LensVL s t a b -> Lens s t a b
lensVL (LensVL Config Config a b -> Lens Config Config a b)
-> LensVL Config Config a b -> Lens Config Config a b
forall a b. (a -> b) -> a -> b
$
\a -> f b
f
( MkConfig
Bool
_searchAll
Maybe Word16
_maxDepth
HashSet OsPath
_exclude
Bool
_filesOnly
Bool
_ignoreDirIntrinsicSize
Maybe (Positive Int)
_numPaths
Bool
_stableSort
Strategy
_strategy
) ->
(Bool -> Config) -> f Bool -> f Config
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
( \Bool
searchAll' ->
Bool
-> Maybe Word16
-> HashSet OsPath
-> Bool
-> Bool
-> Maybe (Positive Int)
-> Bool
-> Strategy
-> Config
MkConfig
Bool
searchAll'
Maybe Word16
_maxDepth
HashSet OsPath
_exclude
Bool
_filesOnly
Bool
_ignoreDirIntrinsicSize
Maybe (Positive Int)
_numPaths
Bool
_stableSort
Strategy
_strategy
)
(a -> f b
f a
Bool
_searchAll)
{-# INLINE labelOptic #-}
instance
(k ~ A_Lens, a ~ Maybe Word16, b ~ Maybe Word16) =>
LabelOptic "maxDepth" k Config Config a b
where
labelOptic :: Optic k NoIx Config Config a b
labelOptic =
LensVL Config Config a b -> Lens Config Config a b
forall s t a b. LensVL s t a b -> Lens s t a b
lensVL (LensVL Config Config a b -> Lens Config Config a b)
-> LensVL Config Config a b -> Lens Config Config a b
forall a b. (a -> b) -> a -> b
$
\a -> f b
f
( MkConfig
Bool
_searchAll
Maybe Word16
_maxDepth
HashSet OsPath
_exclude
Bool
_filesOnly
Bool
_ignoreDirIntrinsicSize
Maybe (Positive Int)
_numPaths
Bool
_stableSort
Strategy
_strategy
) ->
(Maybe Word16 -> Config) -> f (Maybe Word16) -> f Config
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
( \Maybe Word16
maxDepth' ->
Bool
-> Maybe Word16
-> HashSet OsPath
-> Bool
-> Bool
-> Maybe (Positive Int)
-> Bool
-> Strategy
-> Config
MkConfig
Bool
_searchAll
Maybe Word16
maxDepth'
HashSet OsPath
_exclude
Bool
_filesOnly
Bool
_ignoreDirIntrinsicSize
Maybe (Positive Int)
_numPaths
Bool
_stableSort
Strategy
_strategy
)
(a -> f b
f a
Maybe Word16
_maxDepth)
{-# INLINE labelOptic #-}
instance
(k ~ A_Lens, a ~ HashSet OsPath, b ~ HashSet OsPath) =>
LabelOptic "exclude" k Config Config a b
where
labelOptic :: Optic k NoIx Config Config a b
labelOptic =
LensVL Config Config a b -> Lens Config Config a b
forall s t a b. LensVL s t a b -> Lens s t a b
lensVL (LensVL Config Config a b -> Lens Config Config a b)
-> LensVL Config Config a b -> Lens Config Config a b
forall a b. (a -> b) -> a -> b
$
\a -> f b
f
( MkConfig
Bool
_searchAll
Maybe Word16
_maxDepth
HashSet OsPath
_exclude
Bool
_filesOnly
Bool
_ignoreDirIntrinsicSize
Maybe (Positive Int)
_numPaths
Bool
_stableSort
Strategy
_strategy
) ->
(HashSet OsPath -> Config) -> f (HashSet OsPath) -> f Config
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
( \HashSet OsPath
exclude' ->
Bool
-> Maybe Word16
-> HashSet OsPath
-> Bool
-> Bool
-> Maybe (Positive Int)
-> Bool
-> Strategy
-> Config
MkConfig
Bool
_searchAll
Maybe Word16
_maxDepth
HashSet OsPath
exclude'
Bool
_filesOnly
Bool
_ignoreDirIntrinsicSize
Maybe (Positive Int)
_numPaths
Bool
_stableSort
Strategy
_strategy
)
(a -> f b
f a
HashSet OsPath
_exclude)
{-# INLINE labelOptic #-}
instance
(k ~ A_Lens, a ~ Bool, b ~ Bool) =>
LabelOptic "filesOnly" k Config Config a b
where
labelOptic :: Optic k NoIx Config Config a b
labelOptic =
LensVL Config Config a b -> Lens Config Config a b
forall s t a b. LensVL s t a b -> Lens s t a b
lensVL (LensVL Config Config a b -> Lens Config Config a b)
-> LensVL Config Config a b -> Lens Config Config a b
forall a b. (a -> b) -> a -> b
$
\a -> f b
f
( MkConfig
Bool
_searchAll
Maybe Word16
_maxDepth
HashSet OsPath
_exclude
Bool
_filesOnly
Bool
_ignoreDirIntrinsicSize
Maybe (Positive Int)
_numPaths
Bool
_stableSort
Strategy
_strategy
) ->
(Bool -> Config) -> f Bool -> f Config
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
( \Bool
filesOnly' ->
Bool
-> Maybe Word16
-> HashSet OsPath
-> Bool
-> Bool
-> Maybe (Positive Int)
-> Bool
-> Strategy
-> Config
MkConfig
Bool
_searchAll
Maybe Word16
_maxDepth
HashSet OsPath
_exclude
Bool
filesOnly'
Bool
_ignoreDirIntrinsicSize
Maybe (Positive Int)
_numPaths
Bool
_stableSort
Strategy
_strategy
)
(a -> f b
f a
Bool
_filesOnly)
{-# INLINE labelOptic #-}
instance
(k ~ A_Lens, a ~ Bool, b ~ Bool) =>
LabelOptic "ignoreDirIntrinsicSize" k Config Config a b
where
labelOptic :: Optic k NoIx Config Config a b
labelOptic =
LensVL Config Config a b -> Lens Config Config a b
forall s t a b. LensVL s t a b -> Lens s t a b
lensVL (LensVL Config Config a b -> Lens Config Config a b)
-> LensVL Config Config a b -> Lens Config Config a b
forall a b. (a -> b) -> a -> b
$
\a -> f b
f
( MkConfig
Bool
_searchAll
Maybe Word16
_maxDepth
HashSet OsPath
_exclude
Bool
_filesOnly
Bool
_ignoreDirIntrinsicSize
Maybe (Positive Int)
_numPaths
Bool
_stableSort
Strategy
_strategy
) ->
(Bool -> Config) -> f Bool -> f Config
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
( \Bool
ignoreDirIntrinsicSize' ->
Bool
-> Maybe Word16
-> HashSet OsPath
-> Bool
-> Bool
-> Maybe (Positive Int)
-> Bool
-> Strategy
-> Config
MkConfig
Bool
_searchAll
Maybe Word16
_maxDepth
HashSet OsPath
_exclude
Bool
_filesOnly
Bool
ignoreDirIntrinsicSize'
Maybe (Positive Int)
_numPaths
Bool
_stableSort
Strategy
_strategy
)
(a -> f b
f a
Bool
_ignoreDirIntrinsicSize)
{-# INLINE labelOptic #-}
instance
(k ~ A_Lens, a ~ Maybe (Positive Int), b ~ Maybe (Positive Int)) =>
LabelOptic "numPaths" k Config Config a b
where
labelOptic :: Optic k NoIx Config Config a b
labelOptic =
LensVL Config Config a b -> Lens Config Config a b
forall s t a b. LensVL s t a b -> Lens s t a b
lensVL (LensVL Config Config a b -> Lens Config Config a b)
-> LensVL Config Config a b -> Lens Config Config a b
forall a b. (a -> b) -> a -> b
$
\a -> f b
f
( MkConfig
Bool
_searchAll
Maybe Word16
_maxDepth
HashSet OsPath
_exclude
Bool
_filesOnly
Bool
_ignoreDirIntrinsicSize
Maybe (Positive Int)
_numPaths
Bool
_stableSort
Strategy
_strategy
) ->
(Maybe (Positive Int) -> Config)
-> f (Maybe (Positive Int)) -> f Config
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
( \Maybe (Positive Int)
numPaths' ->
Bool
-> Maybe Word16
-> HashSet OsPath
-> Bool
-> Bool
-> Maybe (Positive Int)
-> Bool
-> Strategy
-> Config
MkConfig
Bool
_searchAll
Maybe Word16
_maxDepth
HashSet OsPath
_exclude
Bool
_filesOnly
Bool
_ignoreDirIntrinsicSize
Maybe (Positive Int)
numPaths'
Bool
_stableSort
Strategy
_strategy
)
(a -> f b
f a
Maybe (Positive Int)
_numPaths)
{-# INLINE labelOptic #-}
instance
(k ~ A_Lens, a ~ Bool, b ~ Bool) =>
LabelOptic "stableSort" k Config Config a b
where
labelOptic :: Optic k NoIx Config Config a b
labelOptic =
LensVL Config Config a b -> Lens Config Config a b
forall s t a b. LensVL s t a b -> Lens s t a b
lensVL (LensVL Config Config a b -> Lens Config Config a b)
-> LensVL Config Config a b -> Lens Config Config a b
forall a b. (a -> b) -> a -> b
$
\a -> f b
f
( MkConfig
Bool
_searchAll
Maybe Word16
_maxDepth
HashSet OsPath
_exclude
Bool
_filesOnly
Bool
_ignoreDirIntrinsicSize
Maybe (Positive Int)
_numPaths
Bool
_stableSort
Strategy
_strategy
) ->
(Bool -> Config) -> f Bool -> f Config
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
( \Bool
stableSort' ->
Bool
-> Maybe Word16
-> HashSet OsPath
-> Bool
-> Bool
-> Maybe (Positive Int)
-> Bool
-> Strategy
-> Config
MkConfig
Bool
_searchAll
Maybe Word16
_maxDepth
HashSet OsPath
_exclude
Bool
_filesOnly
Bool
_ignoreDirIntrinsicSize
Maybe (Positive Int)
_numPaths
Bool
stableSort'
Strategy
_strategy
)
(a -> f b
f a
Bool
_stableSort)
{-# INLINE labelOptic #-}
instance
(k ~ A_Lens, a ~ Strategy, b ~ Strategy) =>
LabelOptic "strategy" k Config Config a b
where
labelOptic :: Optic k NoIx Config Config a b
labelOptic =
LensVL Config Config a b -> Lens Config Config a b
forall s t a b. LensVL s t a b -> Lens s t a b
lensVL (LensVL Config Config a b -> Lens Config Config a b)
-> LensVL Config Config a b -> Lens Config Config a b
forall a b. (a -> b) -> a -> b
$
\a -> f b
f
( MkConfig
Bool
_searchAll
Maybe Word16
_maxDepth
HashSet OsPath
_exclude
Bool
_filesOnly
Bool
_ignoreDirIntrinsicSize
Maybe (Positive Int)
_numPaths
Bool
_stableSort
Strategy
_strategy
) ->
(Strategy -> Config) -> f Strategy -> f Config
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
( Bool
-> Maybe Word16
-> HashSet OsPath
-> Bool
-> Bool
-> Maybe (Positive Int)
-> Bool
-> Strategy
-> Config
MkConfig
Bool
_searchAll
Maybe Word16
_maxDepth
HashSet OsPath
_exclude
Bool
_filesOnly
Bool
_ignoreDirIntrinsicSize
Maybe (Positive Int)
_numPaths
Bool
_stableSort
)
(a -> f b
f a
Strategy
_strategy)
{-# INLINE labelOptic #-}
defaultConfig :: Config
defaultConfig :: Config
defaultConfig =
MkConfig
{ searchAll :: Bool
searchAll = Bool
True,
maxDepth :: Maybe Word16
maxDepth = Maybe Word16
forall a. Maybe a
Nothing,
exclude :: HashSet OsPath
exclude = HashSet OsPath
forall a. HashSet a
HSet.empty,
filesOnly :: Bool
filesOnly = Bool
False,
ignoreDirIntrinsicSize :: Bool
ignoreDirIntrinsicSize = Bool
False,
numPaths :: Maybe (Positive Int)
numPaths = Positive Int -> Maybe (Positive Int)
forall a. a -> Maybe a
Just Positive Int
defaultNumPaths,
stableSort :: Bool
stableSort = Bool
False,
strategy :: Strategy
strategy = Strategy
Async
}