Skip to content

Instantly share code, notes, and snippets.

@jeiea
Created February 25, 2017 04:57
Show Gist options
  • Save jeiea/df13a645fdb3ca82be924354e13e8556 to your computer and use it in GitHub Desktop.
Save jeiea/df13a645fdb3ca82be924354e13e8556 to your computer and use it in GitHub Desktop.
Windows CR/LF compatible lines
import ClassyPrelude
-- | Windows CR/LF compatible lines
rLines :: Textual t => t -> [t]
rLines str = res where
(firstLine, rems) = break (\c -> c == '\r' || c == '\n') str
res = case uncons rems of
Nothing -> case uncons firstLine of
Nothing -> []
Just _ -> [firstLine]
Just (x,xs) -> (firstLine :) $ rLines $ if x == '\n' then xs else
case uncons xs of
Just ('\n', rem') -> rem'
_ -> xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment