{-# LANGUAGE TupleSections, Rank2Types #-}

module CabalLenses.Traversals.Internal
   ( traverseDataIf
   , traverseData
   , traverseDependencyIf
   , traverseDependency
   ) where

import CabalLenses.CondVars (CondVars)
import qualified CabalLenses.CondVars as CV
import Distribution.Types.CondTree (CondTree(..), CondBranch(..))
import Distribution.PackageDescription (ConfVar)
import Distribution.Package (Dependency(..))
import Control.Lens (Traversal')

type CondTree' a = CondTree ConfVar [Dependency] a


-- | A traversal for all 'condTreeData' of 'CondTree' that match 'CondVars'.
traverseDataIf :: CondVars -> Traversal' (CondTree' dat) dat
traverseDataIf :: forall dat. CondVars -> Traversal' (CondTree' dat) dat
traverseDataIf CondVars
condVars dat -> f dat
f (CondNode dat
dat [Dependency]
constr [CondBranch ConfVar [Dependency] dat]
comps) =
   dat
-> [Dependency]
-> [CondBranch ConfVar [Dependency] dat]
-> CondTree ConfVar [Dependency] dat
forall v c a. a -> c -> [CondBranch v c a] -> CondTree v c a
CondNode (dat
 -> [Dependency]
 -> [CondBranch ConfVar [Dependency] dat]
 -> CondTree ConfVar [Dependency] dat)
-> f dat
-> f ([Dependency]
      -> [CondBranch ConfVar [Dependency] dat]
      -> CondTree ConfVar [Dependency] dat)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> dat -> f dat
f dat
dat
            f ([Dependency]
   -> [CondBranch ConfVar [Dependency] dat]
   -> CondTree ConfVar [Dependency] dat)
-> f [Dependency]
-> f ([CondBranch ConfVar [Dependency] dat]
      -> CondTree ConfVar [Dependency] dat)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Dependency] -> f [Dependency]
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure [Dependency]
constr
            f ([CondBranch ConfVar [Dependency] dat]
   -> CondTree ConfVar [Dependency] dat)
-> f [CondBranch ConfVar [Dependency] dat]
-> f (CondTree ConfVar [Dependency] dat)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((CondBranch ConfVar [Dependency] dat
 -> f (CondBranch ConfVar [Dependency] dat))
-> [CondBranch ConfVar [Dependency] dat]
-> f [CondBranch ConfVar [Dependency] dat]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse ((CondBranch ConfVar [Dependency] dat
  -> f (CondBranch ConfVar [Dependency] dat))
 -> [CondBranch ConfVar [Dependency] dat]
 -> f [CondBranch ConfVar [Dependency] dat])
-> ((dat -> f dat)
    -> CondBranch ConfVar [Dependency] dat
    -> f (CondBranch ConfVar [Dependency] dat))
-> (dat -> f dat)
-> [CondBranch ConfVar [Dependency] dat]
-> f [CondBranch ConfVar [Dependency] dat]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CondVars
-> (dat -> f dat)
-> CondBranch ConfVar [Dependency] dat
-> f (CondBranch ConfVar [Dependency] dat)
forall {f :: * -> *} {a}.
Applicative f =>
CondVars
-> (a -> f a)
-> CondBranch ConfVar [Dependency] a
-> f (CondBranch ConfVar [Dependency] a)
traverseCompIf CondVars
condVars) dat -> f dat
f [CondBranch ConfVar [Dependency] dat]
comps
   where
      traverseCompIf :: CondVars
-> (a -> f a)
-> CondBranch ConfVar [Dependency] a
-> f (CondBranch ConfVar [Dependency] a)
traverseCompIf CondVars
condVars a -> f a
f (CondBranch Condition ConfVar
cond CondTree ConfVar [Dependency] a
ifComp Maybe (CondTree ConfVar [Dependency] a)
elseComp) =
         Condition ConfVar
-> CondTree ConfVar [Dependency] a
-> Maybe (CondTree ConfVar [Dependency] a)
-> CondBranch ConfVar [Dependency] a
forall v c a.
Condition v
-> CondTree v c a -> Maybe (CondTree v c a) -> CondBranch v c a
CondBranch (Condition ConfVar
 -> CondTree ConfVar [Dependency] a
 -> Maybe (CondTree ConfVar [Dependency] a)
 -> CondBranch ConfVar [Dependency] a)
-> f (Condition ConfVar)
-> f (CondTree ConfVar [Dependency] a
      -> Maybe (CondTree ConfVar [Dependency] a)
      -> CondBranch ConfVar [Dependency] a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Condition ConfVar -> f (Condition ConfVar)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Condition ConfVar
cond f (CondTree ConfVar [Dependency] a
   -> Maybe (CondTree ConfVar [Dependency] a)
   -> CondBranch ConfVar [Dependency] a)
-> f (CondTree ConfVar [Dependency] a)
-> f (Maybe (CondTree ConfVar [Dependency] a)
      -> CondBranch ConfVar [Dependency] a)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> f (CondTree ConfVar [Dependency] a)
ifComp' f (Maybe (CondTree ConfVar [Dependency] a)
   -> CondBranch ConfVar [Dependency] a)
-> f (Maybe (CondTree ConfVar [Dependency] a))
-> f (CondBranch ConfVar [Dependency] a)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> f (Maybe (CondTree ConfVar [Dependency] a))
elseComp'
         where
            ifComp' :: f (CondTree ConfVar [Dependency] a)
ifComp' | Bool
condMatches = CondVars -> Traversal' (CondTree ConfVar [Dependency] a) a
forall dat. CondVars -> Traversal' (CondTree' dat) dat
traverseDataIf CondVars
condVars a -> f a
f CondTree ConfVar [Dependency] a
ifComp
                    | Bool
otherwise   = CondTree ConfVar [Dependency] a
-> f (CondTree ConfVar [Dependency] a)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure CondTree ConfVar [Dependency] a
ifComp

            elseComp' :: f (Maybe (CondTree ConfVar [Dependency] a))
elseComp' | Bool
condMatches = Maybe (CondTree ConfVar [Dependency] a)
-> f (Maybe (CondTree ConfVar [Dependency] a))
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe (CondTree ConfVar [Dependency] a)
elseComp
                      | Bool
otherwise   = ((CondTree ConfVar [Dependency] a
 -> f (CondTree ConfVar [Dependency] a))
-> Maybe (CondTree ConfVar [Dependency] a)
-> f (Maybe (CondTree ConfVar [Dependency] a))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
traverse ((CondTree ConfVar [Dependency] a
  -> f (CondTree ConfVar [Dependency] a))
 -> Maybe (CondTree ConfVar [Dependency] a)
 -> f (Maybe (CondTree ConfVar [Dependency] a)))
-> ((a -> f a)
    -> CondTree ConfVar [Dependency] a
    -> f (CondTree ConfVar [Dependency] a))
-> (a -> f a)
-> Maybe (CondTree ConfVar [Dependency] a)
-> f (Maybe (CondTree ConfVar [Dependency] a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CondVars -> Traversal' (CondTree ConfVar [Dependency] a) a
forall dat. CondVars -> Traversal' (CondTree' dat) dat
traverseDataIf CondVars
condVars) a -> f a
f Maybe (CondTree ConfVar [Dependency] a)
elseComp

            condMatches :: Bool
condMatches = CondVars -> Condition ConfVar -> Bool
CV.eval CondVars
condVars Condition ConfVar
cond


-- | A traversal for all 'condTreeData' (the if and else branches) of the 'CondTree'.
traverseData :: Traversal' (CondTree' dat) dat
traverseData :: forall dat (f :: * -> *).
Applicative f =>
(dat -> f dat) -> CondTree' dat -> f (CondTree' dat)
traverseData dat -> f dat
f (CondNode dat
dat [Dependency]
constr [CondBranch ConfVar [Dependency] dat]
comps) =
   dat
-> [Dependency]
-> [CondBranch ConfVar [Dependency] dat]
-> CondTree ConfVar [Dependency] dat
forall v c a. a -> c -> [CondBranch v c a] -> CondTree v c a
CondNode (dat
 -> [Dependency]
 -> [CondBranch ConfVar [Dependency] dat]
 -> CondTree ConfVar [Dependency] dat)
-> f dat
-> f ([Dependency]
      -> [CondBranch ConfVar [Dependency] dat]
      -> CondTree ConfVar [Dependency] dat)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> dat -> f dat
f dat
dat
            f ([Dependency]
   -> [CondBranch ConfVar [Dependency] dat]
   -> CondTree ConfVar [Dependency] dat)
-> f [Dependency]
-> f ([CondBranch ConfVar [Dependency] dat]
      -> CondTree ConfVar [Dependency] dat)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Dependency] -> f [Dependency]
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure [Dependency]
constr
            f ([CondBranch ConfVar [Dependency] dat]
   -> CondTree ConfVar [Dependency] dat)
-> f [CondBranch ConfVar [Dependency] dat]
-> f (CondTree ConfVar [Dependency] dat)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((CondBranch ConfVar [Dependency] dat
 -> f (CondBranch ConfVar [Dependency] dat))
-> [CondBranch ConfVar [Dependency] dat]
-> f [CondBranch ConfVar [Dependency] dat]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse ((CondBranch ConfVar [Dependency] dat
  -> f (CondBranch ConfVar [Dependency] dat))
 -> [CondBranch ConfVar [Dependency] dat]
 -> f [CondBranch ConfVar [Dependency] dat])
-> ((dat -> f dat)
    -> CondBranch ConfVar [Dependency] dat
    -> f (CondBranch ConfVar [Dependency] dat))
-> (dat -> f dat)
-> [CondBranch ConfVar [Dependency] dat]
-> f [CondBranch ConfVar [Dependency] dat]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (dat -> f dat)
-> CondBranch ConfVar [Dependency] dat
-> f (CondBranch ConfVar [Dependency] dat)
forall {f :: * -> *} {a}.
Applicative f =>
(a -> f a)
-> CondBranch ConfVar [Dependency] a
-> f (CondBranch ConfVar [Dependency] a)
traverseComp) dat -> f dat
f [CondBranch ConfVar [Dependency] dat]
comps
   where
      traverseComp :: (a -> f a)
-> CondBranch ConfVar [Dependency] a
-> f (CondBranch ConfVar [Dependency] a)
traverseComp a -> f a
f (CondBranch Condition ConfVar
cond CondTree ConfVar [Dependency] a
ifComp Maybe (CondTree ConfVar [Dependency] a)
elseComp) =
         Condition ConfVar
-> CondTree ConfVar [Dependency] a
-> Maybe (CondTree ConfVar [Dependency] a)
-> CondBranch ConfVar [Dependency] a
forall v c a.
Condition v
-> CondTree v c a -> Maybe (CondTree v c a) -> CondBranch v c a
CondBranch (Condition ConfVar
 -> CondTree ConfVar [Dependency] a
 -> Maybe (CondTree ConfVar [Dependency] a)
 -> CondBranch ConfVar [Dependency] a)
-> f (Condition ConfVar)
-> f (CondTree ConfVar [Dependency] a
      -> Maybe (CondTree ConfVar [Dependency] a)
      -> CondBranch ConfVar [Dependency] a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Condition ConfVar -> f (Condition ConfVar)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Condition ConfVar
cond
                    f (CondTree ConfVar [Dependency] a
   -> Maybe (CondTree ConfVar [Dependency] a)
   -> CondBranch ConfVar [Dependency] a)
-> f (CondTree ConfVar [Dependency] a)
-> f (Maybe (CondTree ConfVar [Dependency] a)
      -> CondBranch ConfVar [Dependency] a)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (a -> f a)
-> CondTree ConfVar [Dependency] a
-> f (CondTree ConfVar [Dependency] a)
forall dat (f :: * -> *).
Applicative f =>
(dat -> f dat) -> CondTree' dat -> f (CondTree' dat)
traverseData a -> f a
f CondTree ConfVar [Dependency] a
ifComp
                    f (Maybe (CondTree ConfVar [Dependency] a)
   -> CondBranch ConfVar [Dependency] a)
-> f (Maybe (CondTree ConfVar [Dependency] a))
-> f (CondBranch ConfVar [Dependency] a)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((CondTree ConfVar [Dependency] a
 -> f (CondTree ConfVar [Dependency] a))
-> Maybe (CondTree ConfVar [Dependency] a)
-> f (Maybe (CondTree ConfVar [Dependency] a))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
traverse ((CondTree ConfVar [Dependency] a
  -> f (CondTree ConfVar [Dependency] a))
 -> Maybe (CondTree ConfVar [Dependency] a)
 -> f (Maybe (CondTree ConfVar [Dependency] a)))
-> ((a -> f a)
    -> CondTree ConfVar [Dependency] a
    -> f (CondTree ConfVar [Dependency] a))
-> (a -> f a)
-> Maybe (CondTree ConfVar [Dependency] a)
-> f (Maybe (CondTree ConfVar [Dependency] a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> f a)
-> CondTree ConfVar [Dependency] a
-> f (CondTree ConfVar [Dependency] a)
forall dat (f :: * -> *).
Applicative f =>
(dat -> f dat) -> CondTree' dat -> f (CondTree' dat)
traverseData) a -> f a
f Maybe (CondTree ConfVar [Dependency] a)
elseComp


-- | A traversal for all 'condTreeConstraints' of 'CondTree' that match 'CondVars'.
traverseDependencyIf :: CondVars -> Traversal' (CondTree' dat) Dependency
traverseDependencyIf :: forall dat. CondVars -> Traversal' (CondTree' dat) Dependency
traverseDependencyIf CondVars
condVars Dependency -> f Dependency
f (CondNode dat
dat [Dependency]
constr [CondBranch ConfVar [Dependency] dat]
comps) =
   dat
-> [Dependency]
-> [CondBranch ConfVar [Dependency] dat]
-> CondTree ConfVar [Dependency] dat
forall v c a. a -> c -> [CondBranch v c a] -> CondTree v c a
CondNode (dat
 -> [Dependency]
 -> [CondBranch ConfVar [Dependency] dat]
 -> CondTree ConfVar [Dependency] dat)
-> f dat
-> f ([Dependency]
      -> [CondBranch ConfVar [Dependency] dat]
      -> CondTree ConfVar [Dependency] dat)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> dat -> f dat
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure dat
dat
            f ([Dependency]
   -> [CondBranch ConfVar [Dependency] dat]
   -> CondTree ConfVar [Dependency] dat)
-> f [Dependency]
-> f ([CondBranch ConfVar [Dependency] dat]
      -> CondTree ConfVar [Dependency] dat)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Dependency -> f Dependency) -> [Dependency] -> f [Dependency]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse Dependency -> f Dependency
f [Dependency]
constr
            f ([CondBranch ConfVar [Dependency] dat]
   -> CondTree ConfVar [Dependency] dat)
-> f [CondBranch ConfVar [Dependency] dat]
-> f (CondTree ConfVar [Dependency] dat)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((CondBranch ConfVar [Dependency] dat
 -> f (CondBranch ConfVar [Dependency] dat))
-> [CondBranch ConfVar [Dependency] dat]
-> f [CondBranch ConfVar [Dependency] dat]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse ((CondBranch ConfVar [Dependency] dat
  -> f (CondBranch ConfVar [Dependency] dat))
 -> [CondBranch ConfVar [Dependency] dat]
 -> f [CondBranch ConfVar [Dependency] dat])
-> ((Dependency -> f Dependency)
    -> CondBranch ConfVar [Dependency] dat
    -> f (CondBranch ConfVar [Dependency] dat))
-> (Dependency -> f Dependency)
-> [CondBranch ConfVar [Dependency] dat]
-> f [CondBranch ConfVar [Dependency] dat]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CondVars
-> (Dependency -> f Dependency)
-> CondBranch ConfVar [Dependency] dat
-> f (CondBranch ConfVar [Dependency] dat)
forall {f :: * -> *} {a}.
Applicative f =>
CondVars
-> (Dependency -> f Dependency)
-> CondBranch ConfVar [Dependency] a
-> f (CondBranch ConfVar [Dependency] a)
traverseCompIf CondVars
condVars) Dependency -> f Dependency
f [CondBranch ConfVar [Dependency] dat]
comps
   where
      traverseCompIf :: CondVars
-> (Dependency -> f Dependency)
-> CondBranch ConfVar [Dependency] a
-> f (CondBranch ConfVar [Dependency] a)
traverseCompIf CondVars
condVars Dependency -> f Dependency
f (CondBranch Condition ConfVar
cond CondTree ConfVar [Dependency] a
ifComp Maybe (CondTree ConfVar [Dependency] a)
elseComp) =
         Condition ConfVar
-> CondTree ConfVar [Dependency] a
-> Maybe (CondTree ConfVar [Dependency] a)
-> CondBranch ConfVar [Dependency] a
forall v c a.
Condition v
-> CondTree v c a -> Maybe (CondTree v c a) -> CondBranch v c a
CondBranch (Condition ConfVar
 -> CondTree ConfVar [Dependency] a
 -> Maybe (CondTree ConfVar [Dependency] a)
 -> CondBranch ConfVar [Dependency] a)
-> f (Condition ConfVar)
-> f (CondTree ConfVar [Dependency] a
      -> Maybe (CondTree ConfVar [Dependency] a)
      -> CondBranch ConfVar [Dependency] a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Condition ConfVar -> f (Condition ConfVar)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Condition ConfVar
cond f (CondTree ConfVar [Dependency] a
   -> Maybe (CondTree ConfVar [Dependency] a)
   -> CondBranch ConfVar [Dependency] a)
-> f (CondTree ConfVar [Dependency] a)
-> f (Maybe (CondTree ConfVar [Dependency] a)
      -> CondBranch ConfVar [Dependency] a)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> f (CondTree ConfVar [Dependency] a)
ifComp' f (Maybe (CondTree ConfVar [Dependency] a)
   -> CondBranch ConfVar [Dependency] a)
-> f (Maybe (CondTree ConfVar [Dependency] a))
-> f (CondBranch ConfVar [Dependency] a)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> f (Maybe (CondTree ConfVar [Dependency] a))
elseComp'
         where
            ifComp' :: f (CondTree ConfVar [Dependency] a)
ifComp' | Bool
condMatches = CondVars -> Traversal' (CondTree ConfVar [Dependency] a) Dependency
forall dat. CondVars -> Traversal' (CondTree' dat) Dependency
traverseDependencyIf CondVars
condVars Dependency -> f Dependency
f CondTree ConfVar [Dependency] a
ifComp
                    | Bool
otherwise   = CondTree ConfVar [Dependency] a
-> f (CondTree ConfVar [Dependency] a)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure CondTree ConfVar [Dependency] a
ifComp

            elseComp' :: f (Maybe (CondTree ConfVar [Dependency] a))
elseComp' | Bool
condMatches = Maybe (CondTree ConfVar [Dependency] a)
-> f (Maybe (CondTree ConfVar [Dependency] a))
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe (CondTree ConfVar [Dependency] a)
elseComp
                      | Bool
otherwise   = ((CondTree ConfVar [Dependency] a
 -> f (CondTree ConfVar [Dependency] a))
-> Maybe (CondTree ConfVar [Dependency] a)
-> f (Maybe (CondTree ConfVar [Dependency] a))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
traverse ((CondTree ConfVar [Dependency] a
  -> f (CondTree ConfVar [Dependency] a))
 -> Maybe (CondTree ConfVar [Dependency] a)
 -> f (Maybe (CondTree ConfVar [Dependency] a)))
-> ((Dependency -> f Dependency)
    -> CondTree ConfVar [Dependency] a
    -> f (CondTree ConfVar [Dependency] a))
-> (Dependency -> f Dependency)
-> Maybe (CondTree ConfVar [Dependency] a)
-> f (Maybe (CondTree ConfVar [Dependency] a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CondVars -> Traversal' (CondTree ConfVar [Dependency] a) Dependency
forall dat. CondVars -> Traversal' (CondTree' dat) Dependency
traverseDependencyIf CondVars
condVars) Dependency -> f Dependency
f Maybe (CondTree ConfVar [Dependency] a)
elseComp

            condMatches :: Bool
condMatches = CondVars -> Condition ConfVar -> Bool
CV.eval CondVars
condVars Condition ConfVar
cond


-- | A traversal for all 'condTreeConstraints' (the if and else branches) of the 'CondTree'.
traverseDependency :: Traversal' (CondTree' dat) Dependency
traverseDependency :: forall dat (f :: * -> *).
Applicative f =>
(Dependency -> f Dependency) -> CondTree' dat -> f (CondTree' dat)
traverseDependency Dependency -> f Dependency
f (CondNode dat
dat [Dependency]
constr [CondBranch ConfVar [Dependency] dat]
comps) =
   dat
-> [Dependency]
-> [CondBranch ConfVar [Dependency] dat]
-> CondTree ConfVar [Dependency] dat
forall v c a. a -> c -> [CondBranch v c a] -> CondTree v c a
CondNode (dat
 -> [Dependency]
 -> [CondBranch ConfVar [Dependency] dat]
 -> CondTree ConfVar [Dependency] dat)
-> f dat
-> f ([Dependency]
      -> [CondBranch ConfVar [Dependency] dat]
      -> CondTree ConfVar [Dependency] dat)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> dat -> f dat
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure dat
dat
            f ([Dependency]
   -> [CondBranch ConfVar [Dependency] dat]
   -> CondTree ConfVar [Dependency] dat)
-> f [Dependency]
-> f ([CondBranch ConfVar [Dependency] dat]
      -> CondTree ConfVar [Dependency] dat)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Dependency -> f Dependency) -> [Dependency] -> f [Dependency]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse Dependency -> f Dependency
f [Dependency]
constr
            f ([CondBranch ConfVar [Dependency] dat]
   -> CondTree ConfVar [Dependency] dat)
-> f [CondBranch ConfVar [Dependency] dat]
-> f (CondTree ConfVar [Dependency] dat)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((CondBranch ConfVar [Dependency] dat
 -> f (CondBranch ConfVar [Dependency] dat))
-> [CondBranch ConfVar [Dependency] dat]
-> f [CondBranch ConfVar [Dependency] dat]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse ((CondBranch ConfVar [Dependency] dat
  -> f (CondBranch ConfVar [Dependency] dat))
 -> [CondBranch ConfVar [Dependency] dat]
 -> f [CondBranch ConfVar [Dependency] dat])
-> ((Dependency -> f Dependency)
    -> CondBranch ConfVar [Dependency] dat
    -> f (CondBranch ConfVar [Dependency] dat))
-> (Dependency -> f Dependency)
-> [CondBranch ConfVar [Dependency] dat]
-> f [CondBranch ConfVar [Dependency] dat]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Dependency -> f Dependency)
-> CondBranch ConfVar [Dependency] dat
-> f (CondBranch ConfVar [Dependency] dat)
forall {f :: * -> *} {a}.
Applicative f =>
(Dependency -> f Dependency)
-> CondBranch ConfVar [Dependency] a
-> f (CondBranch ConfVar [Dependency] a)
traverseComp) Dependency -> f Dependency
f [CondBranch ConfVar [Dependency] dat]
comps
   where
      traverseComp :: (Dependency -> f Dependency)
-> CondBranch ConfVar [Dependency] a
-> f (CondBranch ConfVar [Dependency] a)
traverseComp Dependency -> f Dependency
f (CondBranch Condition ConfVar
cond CondTree ConfVar [Dependency] a
ifComp Maybe (CondTree ConfVar [Dependency] a)
elseComp) =
         Condition ConfVar
-> CondTree ConfVar [Dependency] a
-> Maybe (CondTree ConfVar [Dependency] a)
-> CondBranch ConfVar [Dependency] a
forall v c a.
Condition v
-> CondTree v c a -> Maybe (CondTree v c a) -> CondBranch v c a
CondBranch (Condition ConfVar
 -> CondTree ConfVar [Dependency] a
 -> Maybe (CondTree ConfVar [Dependency] a)
 -> CondBranch ConfVar [Dependency] a)
-> f (Condition ConfVar)
-> f (CondTree ConfVar [Dependency] a
      -> Maybe (CondTree ConfVar [Dependency] a)
      -> CondBranch ConfVar [Dependency] a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Condition ConfVar -> f (Condition ConfVar)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Condition ConfVar
cond
                    f (CondTree ConfVar [Dependency] a
   -> Maybe (CondTree ConfVar [Dependency] a)
   -> CondBranch ConfVar [Dependency] a)
-> f (CondTree ConfVar [Dependency] a)
-> f (Maybe (CondTree ConfVar [Dependency] a)
      -> CondBranch ConfVar [Dependency] a)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Dependency -> f Dependency)
-> CondTree ConfVar [Dependency] a
-> f (CondTree ConfVar [Dependency] a)
forall dat (f :: * -> *).
Applicative f =>
(Dependency -> f Dependency) -> CondTree' dat -> f (CondTree' dat)
traverseDependency Dependency -> f Dependency
f CondTree ConfVar [Dependency] a
ifComp
                    f (Maybe (CondTree ConfVar [Dependency] a)
   -> CondBranch ConfVar [Dependency] a)
-> f (Maybe (CondTree ConfVar [Dependency] a))
-> f (CondBranch ConfVar [Dependency] a)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((CondTree ConfVar [Dependency] a
 -> f (CondTree ConfVar [Dependency] a))
-> Maybe (CondTree ConfVar [Dependency] a)
-> f (Maybe (CondTree ConfVar [Dependency] a))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
traverse ((CondTree ConfVar [Dependency] a
  -> f (CondTree ConfVar [Dependency] a))
 -> Maybe (CondTree ConfVar [Dependency] a)
 -> f (Maybe (CondTree ConfVar [Dependency] a)))
-> ((Dependency -> f Dependency)
    -> CondTree ConfVar [Dependency] a
    -> f (CondTree ConfVar [Dependency] a))
-> (Dependency -> f Dependency)
-> Maybe (CondTree ConfVar [Dependency] a)
-> f (Maybe (CondTree ConfVar [Dependency] a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Dependency -> f Dependency)
-> CondTree ConfVar [Dependency] a
-> f (CondTree ConfVar [Dependency] a)
forall dat (f :: * -> *).
Applicative f =>
(Dependency -> f Dependency) -> CondTree' dat -> f (CondTree' dat)
traverseDependency) Dependency -> f Dependency
f Maybe (CondTree ConfVar [Dependency] a)
elseComp