mirror of
https://github.com/github/semantic.git
synced 2024-12-22 14:21:31 +03:00
🔥 spanThese.
This commit is contained in:
parent
8a781d0edf
commit
1656f93f65
@ -163,23 +163,6 @@ spanAndSplitFirstLines pred = foldr go ([], [])
|
||||
catThese :: [Join These a] -> Join These [a]
|
||||
catThese as = maybe (Join (These [] [])) Join $ getUnion $ mconcat $ Union . Just . runJoin . fmap pure <$> as
|
||||
|
||||
-- | 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
|
||||
-- | - the left sides of elements which matched only on the right side
|
||||
-- | - the right sides of elements which matched only on the left side
|
||||
-- | - elements which do not intersect.
|
||||
spanThese :: (Join These a -> Join These Bool) -> [[Join These a]] -> ([[Join These a]], [[Join These a]], [[Join These a]], [[Join These a]])
|
||||
spanThese pred children | (child:rest) <- children
|
||||
, not (null child)
|
||||
, ~(moreChildren, moreL, moreR, moreLines) <- spanThese pred rest
|
||||
, ~(l, r) <- split (head child)
|
||||
= case fromThese False False (runJoin (pred (head child))) of
|
||||
(True, True) -> (child : moreChildren, moreL, moreR, moreLines)
|
||||
(True, False) -> (l : moreChildren, moreL, r : moreR, moreLines)
|
||||
(False, True) -> (r : moreChildren, l : moreL, moreR, moreLines)
|
||||
_ -> ([], [], [], children)
|
||||
| ([]:rest) <- children = spanThese pred rest
|
||||
| otherwise = ([], [], [], children)
|
||||
|
||||
pairRangesWithLine :: Monoid b => Join These a -> Join These b -> Join These (a, b)
|
||||
pairRangesWithLine headRanges childLine = fromMaybe (flip (,) mempty <$> headRanges) $ (,) <$> headRanges `applyThese` childLine
|
||||
|
Loading…
Reference in New Issue
Block a user