Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell : words, unwords delimiter

Tags:

haskell

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?

like image 212
Rnet Avatar asked Apr 02 '11 06:04

Rnet


2 Answers

Please also have a look at the genial package split. It provides a module Data.List.Split for all sort of splitting.

like image 168
fuz Avatar answered Sep 23 '22 15:09

fuz


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
like image 36
geekosaur Avatar answered Sep 24 '22 15:09

geekosaur