What is the (or is there an) idiomatic way to strip newlines from strings in Haskell? Or do I have to craft my own by finding the trailing newlines/spaces and then removing them?
EDIT: I’m looking for what Python’s rstrip does, but don’t need the optional “chars” argument:
string.rstrip(s[, chars])
Return a copy of the string with trailing characters removed. If chars
is omitted or None, whitespace
characters are removed. If given and
not None, chars must be a string; the
characters in the string will be
stripped from the end of the string
this method is called on.
Here’s one simple implementation (adapted from Wikipedia):
There’s also an
rstripalready defined inData.String.Utils.(By the way, Hayoo! is a great resource for this kind of question: a search for
rstriptakes you directly toData.String.Utils.)