1
1
mirror of https://github.com/github/semantic.git synced 2025-01-03 21:16:12 +03:00

Add a generalization of adjoin2Lines, parameterized by the selection of an open element.

This commit is contained in:
Rob Rix 2015-12-21 09:52:57 -05:00
parent afafed623c
commit 05785a0b06

View File

@ -291,6 +291,12 @@ adjoin2Lines (EmptyLine : xs) line | Just _ <- openLine xs = EmptyLine : adjoin2
adjoin2Lines (prev:rest) line | Just _ <- openLine [ prev ] = (prev <> line) : rest
adjoin2Lines lines line = line : lines
adjoin2LinesBy :: (a -> Maybe a) -> [Line a] -> Line a -> [Line a]
adjoin2LinesBy _ [] line = [line]
adjoin2LinesBy f (EmptyLine : xs) line | Just _ <- openLineBy f xs = EmptyLine : adjoin2LinesBy f xs line
adjoin2LinesBy f (prev:rest) line | Just _ <- openLineBy f [ prev ] = (prev <> line) : rest
adjoin2LinesBy _ lines line = line : lines
zipWithMaybe :: (Maybe a -> Maybe b -> c) -> [a] -> [b] -> [c]
zipWithMaybe f la lb = take len $ zipWith f la' lb'
where