From b8bc77bb7fb1c46f90fc624481780ee044b2d74a Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 13 Apr 2016 11:47:35 -0400 Subject: [PATCH] Return the heads/tails of children paired. --- src/Alignment.hs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Alignment.hs b/src/Alignment.hs index 392e4e04b..51e1f8289 100644 --- a/src/Alignment.hs +++ b/src/Alignment.hs @@ -153,13 +153,14 @@ 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]], [[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) +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) (intersecting, nonintersecting) = + let ~(l, r) = split first in case fromThese False False . runJoin $ pred first of + (True, True) -> ((first, rest) : intersecting, nonintersecting) + (True, False) -> ((head l, r ++ rest) : intersecting, nonintersecting) + (False, True) -> ((head r, l ++ rest) : intersecting, nonintersecting) + _ -> (intersecting, (first : rest) : nonintersecting) -- | 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