Skip to content

Instantly share code, notes, and snippets.

@JackTheEngineer
Created May 19, 2018 17:20
Show Gist options
  • Save JackTheEngineer/78127defe3196d70d811b6e50d28a15a to your computer and use it in GitHub Desktop.
Save JackTheEngineer/78127defe3196d70d811b6e50d28a15a to your computer and use it in GitHub Desktop.
import Test.QuickCheck
import Data.List (intersperse)
split :: Char -> String -> [String]
split c [] = []
split c xs = xs' : if null xs'' then [] else split c (tail xs'')
where xs' = takeWhile (/=c) xs
xs''= dropWhile (/=c) xs
unsplit :: Char -> [String] -> String
unsplit c = concat . intersperse [c]
-- show
prop_split_inv c xs = unsplit c (split c xs) == xs
main = quickCheck prop_split_inv
-- /show
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment