Proposal: Add split and splitWith (trac #2048)
Twan van Laarhoven
twanvl at gmail.com
Wed Jan 16 18:50:39 EST 2008
Don Stewart wrote:
> I'd like some QuickCheck properties, so we can avoid the unlines . lines /= id
> fiasco. Given that, I'd support this too.
What is a good place to put those?
I just ran some obvious tests from ghci:
> test (\x y -> intercalate [x::Int] (split x y) == y)
] OK, passed 100 tests.
> test (\p xs -> all (not . any p) (splitWith p xs :: [[Int]]))
] OK, passed 100 tests.
for the unbeliever:
> test (\x y -> splitWith (==x) y == split (x::Int) y)
] OK, passed 100 tests.
to show lazyness:
> split 'a' $ concat $ repeat "abcdefgh"
] ["","bcdefgh","bcdefgh","bcdefgh",...
> split 'z' $ concat $ repeat "abcdefgh"
] ["abcdefghabcdefghabcdefghabcdefgh...
Fiasco avoided :)
Twan
More information about the Libraries
mailing list