Why is there no splitBy in the list module?

Christian Maeder maeder at tzi.de
Tue Jul 18 06:08:17 EDT 2006


After all our discussions, I simply want to keep up my old proposal.

It drops a final delimiter and is named using "With" instead of "By" and
therefore would not imply any changes to Data.PackedString.

Isn't that better than changing nothing (after so many people asked for
a split function)?

Christian

Christian Maeder schrieb:
> Simon Marlow schrieb:
>> Would someone like to make a concrete proposal (with code!) for 2-3
>> functions we could reasonably add to Data.List?
> 
> Here is my proposal that is consistent with Data.PackedString and
> "lines" (i.e a final delimiter is ignored -- by extra code)
> 
> {- | The 'splitWith' function takes a predicate and splits the input
> list at each element which satisfies the predicate. -}
> splitWith :: (a -> Bool) -> [a] -> [[a]]
> splitWith p s =
>     case s of
>       [] -> []
>       _ -> let (l, r) = break p s in
>            case r of
>              _ : t@(_ : _) -> l : splitWith p t
>              _ -> [l]
> 
> {- | The 'split' function splits the input list on each occurrence of
> the given element. -}
> split :: Eq a => a -> [a] -> [[a]]
> split c = splitWith (== c)


More information about the Libraries mailing list