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?
Please also have a look at the genial package split. It provides a module Data.List.Split
for all sort of splitting.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With