Skip to content

Instantly share code, notes, and snippets.

@NotTheEconomist
Created October 6, 2017 23:45
Show Gist options
  • Save NotTheEconomist/e47de2ee01ae3fcde1926d9df705a079 to your computer and use it in GitHub Desktop.
Save NotTheEconomist/e47de2ee01ae3fcde1926d9df705a079 to your computer and use it in GitHub Desktop.
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