Skip to content

Instantly share code, notes, and snippets.

@Eugleo
Last active April 17, 2019 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Eugleo/d88608a4f93366afac5bbac6c1faca59 to your computer and use it in GitHub Desktop.
Save Eugleo/d88608a4f93366afac5bbac6c1faca59 to your computer and use it in GitHub Desktop.
-- Seq {aa :: String, gaps :: [(Int, Int)]}
fill' :: Int -> Seq -> String
fill' n Seq {aa = aa, gaps = gaps} = go (sortOn fst gaps) (zip [1 ..] aa) n
where
go :: [(Int, Int)] -> [(Int, Char)] -> Int -> String
go _ [] l = replicate l '-'
go [] str l = map snd str ++ replicate l '-'
go gps@((start, leng):gs) ((i, c):xs) l
| start <= i = replicateAppend leng '-' (c : go gs xs (l - leng - 1))
| otherwise = c : go gps xs (l - 1)
replicateAppend :: Int -> Char -> String -> String
replicateAppend n c str = foldr (\_ b -> c : b) str [1 .. n]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment