1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 14:21:31 +03:00

Return a list of nonintersecting children too.

This commit is contained in:
Rob Rix 2016-04-13 11:41:49 -04:00
parent de05043c67
commit 747bfbf454

View File

@ -153,13 +153,13 @@ group2 ranges children | Just (headRanges, tailRanges) <- unconsThese ranges
| ([]:rest) <- children = group2 ranges rest
| otherwise = ([] <$ ranges, children, fmap (flip (,) []) <$> sequenceL ranges)
spanAndSplitFirstLines :: (Join These a -> Join These Bool) -> [[Join These a]] -> ([Join These a], [[Join These a]])
spanAndSplitFirstLines pred = foldr go ([], [])
where go (first:rest) (fs, rs) = let ~(l, r) = split first in case fromThese False False . runJoin $ pred first of
(True, True) -> (first : fs, rest : rs)
(True, False) -> (head l : fs, (r ++ rest) : rs)
(False, True) -> (head r : fs, (l ++ rest) : rs)
_ -> (fs, (first:rest):rs)
spanAndSplitFirstLines :: (Join These a -> Join These Bool) -> [[Join These a]] -> ([Join These a], [[Join These a]], [[Join These a]])
spanAndSplitFirstLines pred = foldr go ([], [], [])
where go (first : rest) (fs, rs, ns) = let ~(l, r) = split first in case fromThese False False . runJoin $ pred first of
(True, True) -> (first : fs, rest : rs, ns)
(True, False) -> (head l : fs, (r ++ rest) : rs, ns)
(False, True) -> (head r : fs, (l ++ rest) : rs, ns)
_ -> (fs, rs, (first : rest) : ns)
-- | Partitions and splits a list of children into a tuple consisting of:
-- | - elements which matched; if an element matches only partially this field will contain only the matching side