foundation
foundation copied to clipboard
Add a method to the Sequential class to split on an element
The Sequential
class doesn't have a method to split a collection on a specific element (f c = splitOn (== c)
).
This function is called splitOn
in Data.Text and split
in Data.ByteString. Should we call it split
?
I believe there is such function already
Foundation
Foundation actually provides the function to split on a specific element.
splitOn :: (Element c -> Bool) -> c -> [c]
let csv = "col1,col2,col3" :: String
splitOn (== ',') csv === ["col1", "col2", "col3"]
ByteString
ByteString provide a nearly similar one:
split :: Word8 -> ByteString -> [ByteString]
let csv = "col1,col2,col3" :: ByteString -- ignoring the Word8 to Char8 conversion stuff too...
split ',' csv === ["col1", "col2", "col3"]
Text
While it might look similar to ByteString
's or Foundation
's, there is a slight difference where here it is using an other Text
to split on.
splitOn :: Text-> Text -> [Text]
let csv = "col1,col2,col3" :: Text
splitOn (singleton ',') csv === ["col1", "col2", "col3"]
or did you mean you think we should provide a specialised function with Eq (Element col)
as a constraint ?
Yes, I mean a function with the Eq (Element col)
constraint to split on a specific element instead of a predicate. I think this is common enough to be worth including.
fair enough, do split
is a good name indeed.