mirror of
https://github.com/github/semantic.git
synced 2025-01-01 11:46:14 +03:00
Use runBothWith to tidy up a few computations.
This commit is contained in:
parent
51ad3ba049
commit
ae149c94ff
@ -29,7 +29,7 @@ zip = zipWith both
|
||||
-- | Zip two lists by applying a function, using the default values to extend
|
||||
-- | the shorter list.
|
||||
zipWithDefaults :: (a -> a -> b) -> Both a -> Both [a] -> [b]
|
||||
zipWithDefaults f ds as = take (uncurry max $ runBoth (length <$> as)) $ zipWith f ((++) <$> as <*> (repeat <$> ds))
|
||||
zipWithDefaults f ds as = take (runBothWith max (length <$> as)) $ zipWith f ((++) <$> as <*> (repeat <$> ds))
|
||||
|
||||
zipWith :: (a -> a -> b) -> Both [a] -> [b]
|
||||
zipWith _ (Both ([], _)) = []
|
||||
|
@ -75,4 +75,4 @@ diffFiles parser renderer sourceBlobs = do
|
||||
let sources = source <$> sourceBlobs
|
||||
terms <- sequence $ parser <$> sources
|
||||
let replaceLeaves = breakDownLeavesByWord <$> sources
|
||||
return $ renderer (uncurry diffTerms $ runBoth $ replaceLeaves <*> terms) sourceBlobs
|
||||
return $ renderer (runBothWith diffTerms $ replaceLeaves <*> terms) sourceBlobs
|
||||
|
@ -68,7 +68,7 @@ split diff blobs = renderHtml
|
||||
numbered = foldl' numberRows [] rows
|
||||
maxNumber = case numbered of
|
||||
[] -> 0
|
||||
(row : _) -> uncurry max . runBoth $ Prelude.fst <$> row
|
||||
(row : _) -> runBothWith max $ Prelude.fst <$> row
|
||||
|
||||
-- | The number of digits in a number (e.g. 342 has 3 digits).
|
||||
digits :: Int -> Int
|
||||
@ -79,7 +79,7 @@ split diff blobs = renderHtml
|
||||
|
||||
-- | Render a line with numbers as an HTML row.
|
||||
numberedLinesToMarkup :: Both (Int, Line (SplitDiff a Info)) -> Markup
|
||||
numberedLinesToMarkup numberedLines = tr $ uncurry (<>) (runBoth (renderLine <$> numberedLines <*> sources)) <> string "\n"
|
||||
numberedLinesToMarkup numberedLines = tr $ (runBothWith (<>) (renderLine <$> numberedLines <*> sources)) <> string "\n"
|
||||
|
||||
renderLine :: (Int, Line (SplitDiff leaf Info)) -> Source Char -> Markup
|
||||
renderLine (number, line) source = toMarkup $ Renderable (or $ hasChanges <$> line, number, Renderable . (,) source <$> line)
|
||||
|
@ -58,7 +58,7 @@ spec = parallel $ do
|
||||
|
||||
prop "produces the maximum line count in inequal sources" $
|
||||
\ sources ->
|
||||
length (splitAnnotatedByLines sources (getTotalRange <$> sources) (pure mempty) (Indexed $ leafWithRangesInSources sources <$> Both.zip (actualLineRanges <$> (getTotalRange <$> sources) <*> sources))) `shouldBe` uncurry max (runBoth ((+ 1) . length . filter (== '\n') . toList <$> sources))
|
||||
length (splitAnnotatedByLines sources (getTotalRange <$> sources) (pure mempty) (Indexed $ leafWithRangesInSources sources <$> Both.zip (actualLineRanges <$> (getTotalRange <$> sources) <*> sources))) `shouldBe` runBothWith max ((+ 1) . length . filter (== '\n') . toList <$> sources)
|
||||
|
||||
describe "adjoinRowsBy" $ do
|
||||
prop "is identity on top of no rows" $
|
||||
|
Loading…
Reference in New Issue
Block a user