Data.String (original) (raw)

Contents

Description

The String type and associated operations.

Synopsis

Documentation

class IsString a where Source #

Class for string-like datastructures; used by the overloaded string extension (-XOverloadedStrings in GHC).

Functions on strings

lines :: String -> [String] Source #

Splits the argument into a list of lines stripped of their terminatingn characters. The n terminator is optional in a final non-empty line of the argument string.

For example:

>>> lines "" -- empty input contains no lines** **[]

>>> lines "\n" -- single empty line** **[""]

>>> lines "one" -- single unterminated line** **["one"]

>>> lines "one\n" -- single non-empty line** **["one"]

>>> lines "one\n\n" -- second line is empty** **["one",""]

>>> lines "one\ntwo" -- second line is unterminated** **["one","two"]

>>> lines "one\ntwo\n" -- two non-empty lines** **["one","two"]

When the argument string is empty, or ends in a n character, it can be recovered by passing the result of [lines](Data-String.html#v:lines "Data.String") to the [unlines](Data-String.html#v:unlines "Data.String") function. Otherwise, [unlines](Data-String.html#v:unlines "Data.String") appends the missing terminating n. This makesunlines . lines idempotent:

(unlines . lines) . (unlines . lines) = (unlines . lines)

words :: String -> [String] Source #

[words](Data-String.html#v:words "Data.String") breaks a string up into a list of words, which were delimited by white space.

>>> words "Lorem ipsum\ndolor"** **["Lorem","ipsum","dolor"]

unlines :: [String] -> String Source #

Appends a n character to each input string, then concatenates the results. Equivalent to `foldMap` (s -> s `[++](GHC-List.html#v:-43--43- "GHC.List")` "n").

>>> unlines ["Hello", "World", "!"]** **"Hello\nWorld\n!\n"

Note

`[unlines](Data-String.html#v:unlines "Data.String")` `[.](Data-Function.html#v:. "Data.Function")` `[lines](Data-String.html#v:lines "Data.String")` `[/=](Data-Eq.html#v:-47--61- "Data.Eq")` `[id](Data-Function.html#v:id "Data.Function")` when the input is not n-terminated:

>>> unlines . lines $ "foo\nbar"** **"foo\nbar\n"