Skip to content

Instantly share code, notes, and snippets.

@singularitti
Created April 7, 2019 05:34
Show Gist options
  • Save singularitti/fef50413a2803903730b61be07ecf4ae to your computer and use it in GitHub Desktop.
Save singularitti/fef50413a2803903730b61be07ecf4ae to your computer and use it in GitHub Desktop.
Slice a string in Haskell #Haskell #string
-- from [StackOverflow](https://stackoverflow.com/questions/4597820/does-haskell-have-list-slices-i-e-python)
takeStep :: Int -> [a] -> [a]
takeStep _ [] = []
takeStep n (x:xs) = x : takeStep n (drop (n-1) xs)
slice :: Int -> Int -> Int -> [a] -> [a]
slice start stop step = takeStep step . take (stop - start) . drop start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment