alea/Alea/List.hs

12 lines
283 B
Haskell
Raw Normal View History

2014-10-14 18:09:58 +02:00
module Alea.List where
2014-10-13 21:26:55 +02:00
2014-10-14 18:09:58 +02:00
-- Split a list into a list of lists
2014-10-16 23:00:52 +02:00
-- ex. split ',' "ab,cd,ef" == ["ab","cd","ef"]
split :: (Eq a) => a -> [a] -> [[a]]
split _ [] = [[]]
split delim (c:cs)
2014-10-14 18:09:58 +02:00
| c == delim = [] : rest
2014-10-13 21:26:55 +02:00
| otherwise = (c : head rest) : tail rest
where
2014-10-16 23:00:52 +02:00
rest = split delim cs