From 8303fd08ad6091ce02cad00eb7f950e7ee4ca763 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Mon, 29 Feb 2016 08:38:58 -0500 Subject: [PATCH] wrapRowContents applies Both functions to Row contents. --- src/Alignment.hs | 4 ++-- src/Row.hs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Alignment.hs b/src/Alignment.hs index 7d840d13b..f482309d6 100644 --- a/src/Alignment.hs +++ b/src/Alignment.hs @@ -71,7 +71,7 @@ splitTermByLines (Info range categories :< syntax) source = flip (,) range $ cas -- | Split a annotated diff into rows of split diffs. splitAnnotatedByLines :: Both (Source Char) -> Both Range -> Both (Set.Set Category) -> Syntax leaf (Diff leaf Info) -> [Row (SplitDiff leaf Info)] splitAnnotatedByLines sources ranges categories syntax = case syntax of - Leaf a -> wrapRowContents (Free . (`Annotated` Leaf a) . (`Info` fst (runBoth categories)) . unionRanges) (Free . (`Annotated` Leaf a) . (`Info` snd (runBoth categories)) . unionRanges) <$> contextRows ranges sources + Leaf a -> wrapRowContents (((Free . (`Annotated` Leaf a)) .) <$> ((. unionRanges) . flip Info <$> categories)) <$> contextRows ranges sources Indexed children -> adjoinChildRows (Indexed . fmap get) (Identity <$> children) Fixed children -> adjoinChildRows (Fixed . fmap get) (Identity <$> children) Keyed children -> adjoinChildRows (Keyed . Map.fromList) (Map.toList children) @@ -84,7 +84,7 @@ splitAnnotatedByLines sources ranges categories syntax = case syntax of adjoinChildRows :: Has f => ([f (SplitDiff leaf Info)] -> Syntax leaf (SplitDiff leaf Info)) -> [f (Diff leaf Info)] -> [Row (SplitDiff leaf Info)] adjoinChildRows constructor children = let (rows, previous) = foldl childRows ([], start <$> ranges) children in - fmap (wrapRowContents (wrap constructor (fst $ runBoth categories)) (wrap constructor (snd $ runBoth categories))) . adjoin $ rows ++ (fmap Left <$> contextRows (makeRanges previous (end <$> ranges)) sources) + fmap (wrapRowContents (wrap constructor <$> categories)) . adjoin $ rows ++ (fmap Left <$> contextRows (makeRanges previous (end <$> ranges)) sources) wrap :: Has f => ([f (SplitDiff leaf Info)] -> Syntax leaf (SplitDiff leaf Info)) -> Set.Set Category -> [Either Range (f (SplitDiff leaf Info))] -> SplitDiff leaf Info wrap constructor categories children = Free . Annotated (Info (unionRanges $ getRange <$> children) categories) . constructor $ rights children diff --git a/src/Row.hs b/src/Row.hs index b122ee5a9..fc8dac4a3 100644 --- a/src/Row.hs +++ b/src/Row.hs @@ -13,8 +13,8 @@ unRow :: Row a -> Both (Line a) unRow (Row a b) = Both (a, b) -- | Map over both sides of a row with the given functions. -wrapRowContents :: ([a] -> b) -> ([a] -> b) -> Row a -> Row b -wrapRowContents transformLeft transformRight (Row left right) = Row (wrapLineContents transformLeft left) (wrapLineContents transformRight right) +wrapRowContents :: Both ([a] -> b) -> Row a -> Row b +wrapRowContents transform row = uncurry Row . runBoth $ wrapLineContents <$> transform <*> unRow row -- | Given functions that determine whether an item is open, add a row to a -- | first open, non-empty item in a list of rows, or add it as a new row.