on master help sign in
command: Clarify PathTree merging
commit5274e7e443ea0afeba0add01185a7260d36467c8 authorElliot Cameron <eacameron@gmail.com> dateWed 8 Apr 2020, 00:53 (7 years ago) parent5a61bcc
2 files changed+8−5
lib/command/src/Obelisk/Command.hs+5−4 lib/command/src/Obelisk/Command/Run.hs+3−1
lib/command/src/Obelisk/Command.hs+5−4
@@ -464,8 +464,9 @@ resolveHackPaths ps = do
464464 trees <- liftIO $ for ps $ \(p, a) -> pathToTree a <$> canonicalizePath p
465465 pure $ foldr1 mergeRightBias <$> nonEmpty trees
466466 where
467− -- | Merge two 'PathTree's preferring paths on the right in as much as they overlap with paths on the left.
467+ -- | Merge two 'PathTree's preferring leaves on the right in as much as they overlap with paths on the left.
468468 mergeRightBias :: PathTree a -> PathTree a -> PathTree a
469− mergeRightBias (PathTree_Node Nothing a) (PathTree_Node Nothing b) = PathTree_Node Nothing $ Map.unionWith mergeRightBias a b
470− mergeRightBias (PathTree_Node (Just v) _) (PathTree_Node Nothing b) = PathTree_Node (Just v) b
471− mergeRightBias _ b = b
469+ mergeRightBias = go
470+ where
471+ go _ b@(PathTree_Node (Just _) _) = b -- When a leaf is present on the right, right always wins.
472+ go (PathTree_Node v a) (PathTree_Node Nothing b) = PathTree_Node v $ Map.unionWith go a b
lib/command/src/Obelisk/Command/Run.hs+3−1
@@ -96,7 +96,9 @@ data CabalPackageInfo = CabalPackageInfo
9696data HackOn = HackOn_HackOn | HackOn_NoHackOn deriving (Eq, Ord, Show)
9797
9898-- | Describe a set of 'FilePath's as a tree to facilitate merging them in a convenient way.
99−data PathTree a = PathTree_Node (Maybe a) (Map FilePath (PathTree a))
99+data PathTree a = PathTree_Node
100+ (Maybe a) -- An optional leaf at this point in the tree
101+ (Map FilePath (PathTree a)) -- Branches to deeper leaves
100102 deriving (Eq, Ord, Show, Functor, Foldable, Traversable)
101103
102104emptyPathTree :: PathTree a