summaryrefslogtreecommitdiff
path: root/lib/Dirgraph.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Dirgraph.hs')
-rw-r--r--lib/Dirgraph.hs18
1 files changed, 8 insertions, 10 deletions
diff --git a/lib/Dirgraph.hs b/lib/Dirgraph.hs
index b97a644..4873228 100644
--- a/lib/Dirgraph.hs
+++ b/lib/Dirgraph.hs
@@ -1,23 +1,21 @@
-{-# LANGUAGE LambdaCase #-}
-{-# LANGUAGE TupleSections #-}
+{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE LambdaCase #-}
+{-# LANGUAGE TupleSections #-}
-- | Simple directed graphs, for dependency checking
module Dirgraph where
+import Universum
import CheckMap (MapResult (mapresultDepends))
-import Control.Monad (forM_)
-import Data.Functor ((<&>))
-import Data.Map.Strict (Map, mapMaybeWithKey, mapWithKey,
- traverseWithKey)
+import Data.Map.Strict (mapMaybeWithKey, mapWithKey, traverseWithKey)
import qualified Data.Map.Strict as M
-import Data.Set (Set, (\\))
+import Data.Set ((\\))
import qualified Data.Set as S
import Paths (normalise)
import Text.Dot (Dot, (.->.))
import qualified Text.Dot as D
import Types (Dep (LocalMap))
-import Witherable (mapMaybe)
-- | a simple directed graph
type Graph a = Map a (Set a)
@@ -26,7 +24,7 @@ nodes :: Graph a -> Set a
nodes = M.keysSet
-- | simple directed graph of exits
-resultToGraph :: Map FilePath MapResult -> Graph FilePath
+resultToGraph :: Map FilePath (MapResult a) -> Graph FilePath
resultToGraph = fmap (S.fromList . mapMaybe onlyLocalMaps . mapresultDepends)
where onlyLocalMaps = \case
LocalMap path -> Just (normalise "" path)
@@ -35,7 +33,7 @@ resultToGraph = fmap (S.fromList . mapMaybe onlyLocalMaps . mapresultDepends)
-- | invert edges of a directed graph
invertGraph :: (Eq a, Ord a) => Graph a -> Graph a
invertGraph graph = mapWithKey collectFroms graph
- where collectFroms to _ = S.fromList . M.elems . mapMaybeWithKey (select to) $ graph
+ where collectFroms to _ = S.fromList . elems . mapMaybeWithKey (select to) $ graph
select to from elems = if to `elem` elems then Just from else Nothing
-- | all nodes reachable from some entrypoint