Last active
April 17, 2019 13:08
-
-
Save Eugleo/d88608a4f93366afac5bbac6c1faca59 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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