17 lines
455 B
Haskell
17 lines
455 B
Haskell
|
module List where
|
||
|
|
||
|
-- Remove the nth element of a list. (0-indexed)
|
||
|
-- RemoveAt 2 "abc" == ('c', "ab")
|
||
|
removeAt :: Int -> [a] -> (a, [a])
|
||
|
removeAt n xs = (xs !! n, take n xs ++ drop (n+1) xs)
|
||
|
|
||
|
-- Split a string into a list of strings
|
||
|
-- ex. split "ab,cd,ef" ',' == ["ab","cd","ef"]
|
||
|
split :: String -> Char -> [String]
|
||
|
split [] _ = [""]
|
||
|
split (c:cs) delim
|
||
|
| c == delim = "" : rest
|
||
|
| otherwise = (c : head rest) : tail rest
|
||
|
where
|
||
|
rest = split cs delim
|