Fix List.split
This commit makes List.split behave a bit more sane and elegantly.
Currently split has the following behaviour:
0: split (== ':") "foo" -> ["foo"]
1: split (== ':") ":foo" -> ["", "foo"]
2: split (== ':") "foo:" -> ["foo"] (!!)
3: split (== ':') ":foo:foo" -> ["", "foo", "foo"]
4: split (== ':') ":foo" -> ["", "foo"]
5: split (== ':') "" -> [] (!!)
Cases 3 and 5 are the problematic ones. I would think they would result
in ["foo", ""] and [""] respectively. This patch gives split this
behaviour, it also gives split the nice property that the length of
(split ':' str) is (1 + the number of colons in str)
I've looked at the uses of split in the prelude and none of them seem to
be effected by this change.
commit70b6f8fde18a0888f9864d454f9aa05b665bd564
authorAndrew Cann <shum@canndrew.org>
dateSun 11 May 2014, 21:09 (12 years ago)
parentd9a96d1
libs/prelude/Prelude/List.idr−1
@@ -532,7 +532,6 @@ break : (a -> Bool) -> List a -> (List a, List a)
532532break p = span (not . p)
533533
534534split : (a -> Bool) -> List a -> List (List a)
535−split p [] = []
536535split p xs =
537536 case break p xs of
538537 (chunk, []) => [chunk]