Haskell: words, word delimiter

Is there a way to provide a separator for words and unwords in haskell to make it look like split and join in python?

+7
source share
3 answers

No, but they are really simple (optimized versions) of the Data.List.break and Data.List.intersperse respectively.

 pythonicSplit :: String -> Char -> [String] pythonicSplit "" _ = [] pythonicSplit sc = let (r,rs) = break (== c) s in r : pythonicSplit rs c pythonicJoin :: [String] -> Char -> String pythonicJoin ss c = intersperse c ss -- or: flip intersperse 
+4
source

Also pay attention to the separation of ingenious packages. It provides the Data.List.Split module for all kinds of splits.

+11
source

Text has splitOn and intercalate , which is equivalent to Python split and join .

0
source

All Articles