{-# LANGUAGE Rank2Types #-}

module CabalLenses.Traversals.Dependency
   ( allDependency
   , allDependencyIf
   , dependency
   , dependencyIf
   ) where

import CabalLenses.Section (Section(..))
import CabalLenses.Traversals.Internal (traverseDependency, traverseDependencyIf)
import CabalLenses.CondVars (CondVars)
import CabalLenses.PackageDescription
import Control.Lens
import Distribution.PackageDescription (GenericPackageDescription(GenericPackageDescription))
import Distribution.Package (Dependency)
import Distribution.Types.UnqualComponentName (unUnqualComponentName)


-- | A traversal for all 'Dependency' of all 'Section'.
allDependency :: Traversal' GenericPackageDescription Dependency
allDependency :: Traversal' GenericPackageDescription Dependency
allDependency Dependency -> f Dependency
f (GenericPackageDescription PackageDescription
descrp Maybe Version
gpdVers [PackageFlag]
flags Maybe (CondTree ConfVar [Dependency] Library)
lib [(UnqualComponentName, CondTree ConfVar [Dependency] Library)]
subLibs [(UnqualComponentName, CondTree ConfVar [Dependency] ForeignLib)]
foreignLibs [(UnqualComponentName, CondTree ConfVar [Dependency] Executable)]
exes [(UnqualComponentName, CondTree ConfVar [Dependency] TestSuite)]
tests [(UnqualComponentName, CondTree ConfVar [Dependency] Benchmark)]
benchs) =
   PackageDescription
-> Maybe Version
-> [PackageFlag]
-> Maybe (CondTree ConfVar [Dependency] Library)
-> [(UnqualComponentName, CondTree ConfVar [Dependency] Library)]
-> [(UnqualComponentName,
     CondTree ConfVar [Dependency] ForeignLib)]
-> [(UnqualComponentName,
     CondTree ConfVar [Dependency] Executable)]
-> [(UnqualComponentName, CondTree ConfVar [Dependency] TestSuite)]
-> [(UnqualComponentName, CondTree ConfVar [Dependency] Benchmark)]
-> GenericPackageDescription
GenericPackageDescription forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (f :: * -> *) a. Applicative f => a -> f a
pure PackageDescription
descrp
                             forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Version
gpdVers
                             forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *) a. Applicative f => a -> f a
pure [PackageFlag]
flags
                             forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (forall a b. Prism (Maybe a) (Maybe b) a b
_Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall dat. Traversal' (CondTree' dat) Dependency
traverseDependency) Dependency -> f Dependency
f Maybe (CondTree ConfVar [Dependency] Library)
lib
                             forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *) a. Applicative f => a -> f a
pure [(UnqualComponentName, CondTree ConfVar [Dependency] Library)]
subLibs
                             forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *) a. Applicative f => a -> f a
pure [(UnqualComponentName, CondTree ConfVar [Dependency] ForeignLib)]
foreignLibs
                             forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s t a b. Field2 s t a b => Lens s t a b
_2 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall dat. Traversal' (CondTree' dat) Dependency
traverseDependency) Dependency -> f Dependency
f [(UnqualComponentName, CondTree ConfVar [Dependency] Executable)]
exes
                             forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s t a b. Field2 s t a b => Lens s t a b
_2 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall dat. Traversal' (CondTree' dat) Dependency
traverseDependency) Dependency -> f Dependency
f [(UnqualComponentName, CondTree ConfVar [Dependency] TestSuite)]
tests
                             forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s t a b. Field2 s t a b => Lens s t a b
_2 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall dat. Traversal' (CondTree' dat) Dependency
traverseDependency) Dependency -> f Dependency
f [(UnqualComponentName, CondTree ConfVar [Dependency] Benchmark)]
benchs


-- | A traversal for all 'Dependency' of all 'Section' that match 'CondVars'.
allDependencyIf :: CondVars -> Traversal' GenericPackageDescription Dependency
allDependencyIf :: CondVars -> Traversal' GenericPackageDescription Dependency
allDependencyIf CondVars
condVars Dependency -> f Dependency
f (GenericPackageDescription PackageDescription
descrp Maybe Version
gpdVers [PackageFlag]
flags Maybe (CondTree ConfVar [Dependency] Library)
lib [(UnqualComponentName, CondTree ConfVar [Dependency] Library)]
subLibs [(UnqualComponentName, CondTree ConfVar [Dependency] ForeignLib)]
foreignLibs [(UnqualComponentName, CondTree ConfVar [Dependency] Executable)]
exes [(UnqualComponentName, CondTree ConfVar [Dependency] TestSuite)]
tests [(UnqualComponentName, CondTree ConfVar [Dependency] Benchmark)]
benchs) =
   PackageDescription
-> Maybe Version
-> [PackageFlag]
-> Maybe (CondTree ConfVar [Dependency] Library)
-> [(UnqualComponentName, CondTree ConfVar [Dependency] Library)]
-> [(UnqualComponentName,
     CondTree ConfVar [Dependency] ForeignLib)]
-> [(UnqualComponentName,
     CondTree ConfVar [Dependency] Executable)]
-> [(UnqualComponentName, CondTree ConfVar [Dependency] TestSuite)]
-> [(UnqualComponentName, CondTree ConfVar [Dependency] Benchmark)]
-> GenericPackageDescription
GenericPackageDescription forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (f :: * -> *) a. Applicative f => a -> f a
pure PackageDescription
descrp
                             forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Version
gpdVers
                             forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *) a. Applicative f => a -> f a
pure [PackageFlag]
flags
                             forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (forall a b. Prism (Maybe a) (Maybe b) a b
_Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall dat. CondVars -> Traversal' (CondTree' dat) Dependency
traverseDependencyIf CondVars
condVars) Dependency -> f Dependency
f Maybe (CondTree ConfVar [Dependency] Library)
lib
                             forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *) a. Applicative f => a -> f a
pure [(UnqualComponentName, CondTree ConfVar [Dependency] Library)]
subLibs
                             forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *) a. Applicative f => a -> f a
pure [(UnqualComponentName, CondTree ConfVar [Dependency] ForeignLib)]
foreignLibs
                             forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s t a b. Field2 s t a b => Lens s t a b
_2 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall dat. CondVars -> Traversal' (CondTree' dat) Dependency
traverseDependencyIf CondVars
condVars) Dependency -> f Dependency
f [(UnqualComponentName, CondTree ConfVar [Dependency] Executable)]
exes
                             forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s t a b. Field2 s t a b => Lens s t a b
_2 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall dat. CondVars -> Traversal' (CondTree' dat) Dependency
traverseDependencyIf CondVars
condVars) Dependency -> f Dependency
f [(UnqualComponentName, CondTree ConfVar [Dependency] TestSuite)]
tests
                             forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s t a b. Field2 s t a b => Lens s t a b
_2 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall dat. CondVars -> Traversal' (CondTree' dat) Dependency
traverseDependencyIf CondVars
condVars) Dependency -> f Dependency
f [(UnqualComponentName, CondTree ConfVar [Dependency] Benchmark)]
benchs


-- | A traversal for all 'Dependency' of 'Section'.
dependency :: Section -> Traversal' GenericPackageDescription Dependency
dependency :: Section -> Traversal' GenericPackageDescription Dependency
dependency Section
Library           = Lens'
  GenericPackageDescription
  (Maybe (CondTree ConfVar [Dependency] Library))
condLibraryL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. Prism (Maybe a) (Maybe b) a b
_Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall dat. Traversal' (CondTree' dat) Dependency
traverseDependency
dependency (Executable Name
name) = Lens'
  GenericPackageDescription
  [(UnqualComponentName, CondTree ConfVar [Dependency] Executable)]
condExecutablesL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {p :: * -> * -> *} {f :: * -> *} {b}.
(Choice p, Applicative f) =>
Name
-> Optic' p f (UnqualComponentName, b) (UnqualComponentName, b)
having Name
name forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s t a b. Field2 s t a b => Lens s t a b
_2 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall dat. Traversal' (CondTree' dat) Dependency
traverseDependency
dependency (TestSuite Name
name)  = Lens'
  GenericPackageDescription
  [(UnqualComponentName, CondTree ConfVar [Dependency] TestSuite)]
condTestSuitesL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {p :: * -> * -> *} {f :: * -> *} {b}.
(Choice p, Applicative f) =>
Name
-> Optic' p f (UnqualComponentName, b) (UnqualComponentName, b)
having Name
name forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s t a b. Field2 s t a b => Lens s t a b
_2 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall dat. Traversal' (CondTree' dat) Dependency
traverseDependency
dependency (Benchmark Name
name)  = Lens'
  GenericPackageDescription
  [(UnqualComponentName, CondTree ConfVar [Dependency] Benchmark)]
condBenchmarksL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {p :: * -> * -> *} {f :: * -> *} {b}.
(Choice p, Applicative f) =>
Name
-> Optic' p f (UnqualComponentName, b) (UnqualComponentName, b)
having Name
name forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s t a b. Field2 s t a b => Lens s t a b
_2 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall dat. Traversal' (CondTree' dat) Dependency
traverseDependency


-- | A traversal for the 'Dependency' of 'Section' that match 'CondVars'.
dependencyIf :: CondVars -> Section -> Traversal' GenericPackageDescription Dependency
dependencyIf :: CondVars
-> Section -> Traversal' GenericPackageDescription Dependency
dependencyIf CondVars
condVars Section
Library           = Lens'
  GenericPackageDescription
  (Maybe (CondTree ConfVar [Dependency] Library))
condLibraryL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. Prism (Maybe a) (Maybe b) a b
_Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall dat. CondVars -> Traversal' (CondTree' dat) Dependency
traverseDependencyIf CondVars
condVars
dependencyIf CondVars
condVars (Executable Name
name) = Lens'
  GenericPackageDescription
  [(UnqualComponentName, CondTree ConfVar [Dependency] Executable)]
condExecutablesL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {p :: * -> * -> *} {f :: * -> *} {b}.
(Choice p, Applicative f) =>
Name
-> Optic' p f (UnqualComponentName, b) (UnqualComponentName, b)
having Name
name forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s t a b. Field2 s t a b => Lens s t a b
_2 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall dat. CondVars -> Traversal' (CondTree' dat) Dependency
traverseDependencyIf CondVars
condVars
dependencyIf CondVars
condVars (TestSuite Name
name)  = Lens'
  GenericPackageDescription
  [(UnqualComponentName, CondTree ConfVar [Dependency] TestSuite)]
condTestSuitesL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {p :: * -> * -> *} {f :: * -> *} {b}.
(Choice p, Applicative f) =>
Name
-> Optic' p f (UnqualComponentName, b) (UnqualComponentName, b)
having Name
name forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s t a b. Field2 s t a b => Lens s t a b
_2 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall dat. CondVars -> Traversal' (CondTree' dat) Dependency
traverseDependencyIf CondVars
condVars
dependencyIf CondVars
condVars (Benchmark Name
name)  = Lens'
  GenericPackageDescription
  [(UnqualComponentName, CondTree ConfVar [Dependency] Benchmark)]
condBenchmarksL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {p :: * -> * -> *} {f :: * -> *} {b}.
(Choice p, Applicative f) =>
Name
-> Optic' p f (UnqualComponentName, b) (UnqualComponentName, b)
having Name
name forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s t a b. Field2 s t a b => Lens s t a b
_2 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall dat. CondVars -> Traversal' (CondTree' dat) Dependency
traverseDependencyIf CondVars
condVars


having :: Name
-> Optic' p f (UnqualComponentName, b) (UnqualComponentName, b)
having Name
name = forall (p :: * -> * -> *) (f :: * -> *) a.
(Choice p, Applicative f) =>
(a -> Bool) -> Optic' p f a a
filtered ((forall a. Eq a => a -> a -> Bool
== Name
name) forall b c a. (b -> c) -> (a -> b) -> a -> c
. UnqualComponentName -> Name
unUnqualComponentName forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst)