From f7b4ecc1c1b374535107f758381eb69beb5f24de Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Mon, 7 Mar 2016 19:36:16 -0500 Subject: [PATCH] Rename adjoinRowsByR to adjoinRowsBy. --- src/Alignment.hs | 2 +- src/Row.hs | 16 ++++++++-------- test/AlignmentSpec.hs | 12 ++++++------ 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Alignment.hs b/src/Alignment.hs index 436608016..ad5b24709 100644 --- a/src/Alignment.hs +++ b/src/Alignment.hs @@ -77,7 +77,7 @@ splitAnnotatedByLines sources infos syntax = case syntax of adjoinChildRows :: (Copointed f, Functor f) => ([f (SplitDiff leaf Info)] -> Syntax leaf (SplitDiff leaf Info)) -> [f [Row (SplitDiff leaf Info, Range)]] -> [Row (SplitDiff leaf Info, Range)] adjoinChildRows constructor children = let (rows, next) = foldr childRows ([], end <$> ranges) children in - fmap (Row . (wrapLineContents <$> (makeBranchTerm (\ info -> Free . Annotated info . constructor) <$> categories <*> next) <*>) . unRow) . foldr (adjoinRowsByR (openRangePair <$> sources)) [] + fmap (Row . (wrapLineContents <$> (makeBranchTerm (\ info -> Free . Annotated info . constructor) <$> categories <*> next) <*>) . unRow) . foldr (adjoinRowsBy (openRangePair <$> sources)) [] $ zipWithDefaults makeRow (pure mempty) (fmap (pure . (,) Nothing) <$> (actualLineRanges <$> (Range <$> (start <$> ranges) <*> next) <*> sources)) ++ rows childRows :: (Copointed f, Functor f) => f [Row (SplitDiff leaf Info, Range)] -> ([Row (Maybe (f (SplitDiff leaf Info)), Range)], Both Int) -> ([Row (Maybe (f (SplitDiff leaf Info)), Range)], Both Int) diff --git a/src/Row.hs b/src/Row.hs index f86e5b71a..0f58da7cd 100644 --- a/src/Row.hs +++ b/src/Row.hs @@ -23,20 +23,20 @@ isOpenRowBy :: Both (MaybeOpen a) -> Row a -> Bool isOpenRowBy f = runBothWith (&&) . (isOpenLineBy <$> f <*>) . unRow -- | Merge open lines and prepend closed lines (as determined by a pair of functions) onto a list of rows. -adjoinRowsByR :: Both (MaybeOpen a) -> Row a -> [Row a] -> [Row a] -adjoinRowsByR _ (Row (Both (EmptyLine, EmptyLine))) rows = rows +adjoinRowsBy :: Both (MaybeOpen a) -> Row a -> [Row a] -> [Row a] +adjoinRowsBy _ (Row (Both (EmptyLine, EmptyLine))) rows = rows -adjoinRowsByR f row (nextRow : rows) | isOpenRowBy f row = Row ((<>) <$> unRow row <*> unRow nextRow) : rows +adjoinRowsBy f row (nextRow : rows) | isOpenRowBy f row = Row ((<>) <$> unRow row <*> unRow nextRow) : rows -adjoinRowsByR f (Row (Both (EmptyLine, right))) (Row (Both (nextLeft, nextRight)) : rows) | isOpenLineBy (fst f) nextLeft = makeRow nextLeft right : adjoinRowsByR f (makeRow mempty nextRight) rows +adjoinRowsBy f (Row (Both (EmptyLine, right))) (Row (Both (nextLeft, nextRight)) : rows) | isOpenLineBy (fst f) nextLeft = makeRow nextLeft right : adjoinRowsBy f (makeRow mempty nextRight) rows -adjoinRowsByR f (Row (Both (left, right))) (Row (Both (nextLeft, nextRight)) : rows) | isOpenLineBy (fst f) left = makeRow (left <> nextLeft) right : adjoinRowsByR f (makeRow mempty nextRight) rows +adjoinRowsBy f (Row (Both (left, right))) (Row (Both (nextLeft, nextRight)) : rows) | isOpenLineBy (fst f) left = makeRow (left <> nextLeft) right : adjoinRowsBy f (makeRow mempty nextRight) rows -adjoinRowsByR f (Row (Both (left, EmptyLine))) (Row (Both (nextLeft, nextRight)) : rows) | isOpenLineBy (snd f) nextRight = makeRow left nextRight : adjoinRowsByR f (makeRow nextLeft mempty) rows +adjoinRowsBy f (Row (Both (left, EmptyLine))) (Row (Both (nextLeft, nextRight)) : rows) | isOpenLineBy (snd f) nextRight = makeRow left nextRight : adjoinRowsBy f (makeRow nextLeft mempty) rows -adjoinRowsByR f (Row (Both (left, right))) (Row (Both (nextLeft, nextRight)) : rows) | isOpenLineBy (snd f) right = makeRow left (right <> nextRight) : adjoinRowsByR f (makeRow nextLeft mempty) rows +adjoinRowsBy f (Row (Both (left, right))) (Row (Both (nextLeft, nextRight)) : rows) | isOpenLineBy (snd f) right = makeRow left (right <> nextRight) : adjoinRowsBy f (makeRow nextLeft mempty) rows -adjoinRowsByR _ row rows = row : rows +adjoinRowsBy _ row rows = row : rows instance Show a => Show (Row a) where show (Row (Both (left, right))) = "\n" ++ show left ++ " | " ++ show right diff --git a/test/AlignmentSpec.hs b/test/AlignmentSpec.hs index 6eb3cef35..0741e2f57 100644 --- a/test/AlignmentSpec.hs +++ b/test/AlignmentSpec.hs @@ -74,26 +74,26 @@ spec = parallel $ do describe "adjoinRowsBy" $ do prop "is identity on top of no rows" $ forAll (arbitrary `suchThat` (not . isEmptyRow)) $ - \ a -> adjoinRowsByR (pure openMaybe) a [] `shouldBe` [ a ] + \ a -> adjoinRowsBy (pure openMaybe) a [] `shouldBe` [ a ] prop "prunes empty rows" $ - \ a -> adjoinRowsByR (pure openMaybe) (makeRow EmptyLine EmptyLine) [ a ] `shouldBe` [ a ] + \ a -> adjoinRowsBy (pure openMaybe) (makeRow EmptyLine EmptyLine) [ a ] `shouldBe` [ a ] prop "merges open rows" $ forAll ((arbitrary `suchThat` isOpenBy openMaybe) >>= \ a -> (,) a <$> arbitrary) $ - \ (a, b) -> adjoinRowsByR (pure openMaybe) a [ b ] `shouldBe` [ Row (mappend <$> unRow a <*> unRow b) ] + \ (a, b) -> adjoinRowsBy (pure openMaybe) a [ b ] `shouldBe` [ Row (mappend <$> unRow a <*> unRow b) ] prop "prepends closed rows" $ forAll ((arbitrary `suchThat` isClosedBy openMaybe) >>= \ a -> (,) a <$> arbitrary) $ - \ (a, b) -> adjoinRowsByR (pure openMaybe) a [ b ] `shouldBe` [ a, b ] + \ (a, b) -> adjoinRowsBy (pure openMaybe) a [ b ] `shouldBe` [ a, b ] prop "does not promote empty lines through closed rows" $ forAll ((arbitrary `suchThat` (not . isOpenLineBy openMaybe)) >>= \ a -> (,) a <$> arbitrary) $ - \ (a, b) -> adjoinRowsByR (pure openMaybe) (makeRow EmptyLine a) [ makeRow a a, b ] `shouldBe` [ makeRow a a, b ] + \ (a, b) -> adjoinRowsBy (pure openMaybe) (makeRow EmptyLine a) [ makeRow a a, b ] `shouldBe` [ makeRow a a, b ] prop "promotes empty lines through open rows" $ forAll ((arbitrary `suchThat` (\ (a, b) -> isOpenLineBy openMaybe a && not (isOpenLineBy openMaybe b))) >>= \ (a, b) -> (,,) a b <$> arbitrary) $ - \ (open, closed, rest) -> adjoinRowsByR (pure openMaybe) (makeRow EmptyLine open) [ makeRow open closed, rest ] `shouldBe` [ makeRow open closed, makeRow EmptyLine open, rest ] + \ (open, closed, rest) -> adjoinRowsBy (pure openMaybe) (makeRow EmptyLine open) [ makeRow open closed, rest ] `shouldBe` [ makeRow open closed, makeRow EmptyLine open, rest ] describe "splitAbstractedTerm" $ do prop "preserves line count" $