Reputation: 5040
Is there any way I can provide a delimiter to words
and unwords
in haskell, to make it similar to split and join in python?
Upvotes: 9
Views: 3901
Reputation: 1243
Text has splitOn & intercalate which is equivalent to Python's split
& join
.
Upvotes: 1
Reputation: 93107
Please also have a look at the genial package split. It provides a module Data.List.Split
for all sort of splitting.
Upvotes: 10
Reputation: 61449
No, but they're really just (optimized versions of) applications of Data.List.break
and Data.List.intersperse
, respectively.
pythonicSplit :: String -> Char -> [String]
pythonicSplit "" _ = []
pythonicSplit s c = let (r,rs) = break (== c) s
in r : pythonicSplit rs c
pythonicJoin :: [String] -> Char -> String
pythonicJoin ss c = intersperse c ss -- or: flip intersperse
Upvotes: 4