Created
October 6, 2017 23:45
-
-
Save NotTheEconomist/e47de2ee01ae3fcde1926d9df705a079 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
import Data.List.Split(splitOn) | |
import qualified Data.Text as T | |
parse :: String -> [Int] | |
parse s | '-' `elem` s = expandedS | |
| otherwise = singleS | |
where expandedS = let (x':(y':[])) = splitOn "-" s | |
x = read x' :: Int | |
y = read y' :: Int | |
in [x..y] | |
singleS = [read s :: Int] | |
parseranges :: String -> [Int] | |
parseranges s = let chunks = map (T.unpack . T.strip . T.pack) $ splitOn "," s | |
in [x | chunk <- chunks, x <- parse chunk] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment