headroom-0.3.1.0: License Header Manager

Copyright(c) 2019-2020 Vaclav Svejcar
LicenseBSD-3-Clause
Maintainervaclav.svejcar@gmail.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Headroom.Data.TextExtra

Contents

Description

Module containing bunch of useful functions for working with text.

Synopsis

Documentation

read Source #

Arguments

:: Read a 
=> Text

input text to parse

-> Maybe a

parsed value

Same as readMaybe, but takes Text as input instead of String.

>>> read "123" :: Maybe Int
Just 123

Working with text lines

mapLines Source #

Arguments

:: (Text -> Text)

function to map over individual lines

-> Text

input text

-> Text

result text

Maps given function over individual lines of the given text.

>>> mapLines ("T: " <>) "foo zz\nbar"
"T: foo zz\nT: bar"

fromLines Source #

Arguments

:: [Text]

lines to join

-> Text

text joined from individual lines

Similar to unlines, but does not automatically adds n at the end of the text. Advantage is that when used together with toLines, it doesn't ocassionaly change the newlines ad the end of input text:

>>> fromLines . toLines $ "foo\nbar"
"foo\nbar"
>>> fromLines . toLines $ "foo\nbar\n"
"foo\nbar\n"

Other examples:

>>> fromLines []
""
>>> fromLines ["foo"]
"foo"
>>> fromLines ["first", "second"]
"first\nsecond"
>>> fromLines ["first", "second", ""]
"first\nsecond\n"

toLines Source #

Arguments

:: Text

text to break into lines

-> [Text]

lines of input text

Similar to lines, but does not drop trailing newlines from output. Advantage is that when used together with fromLines, it doesn't ocassionaly change the newlines ad the end of input text:

>>> fromLines . toLines $ "foo\nbar"
"foo\nbar"
>>> fromLines . toLines $ "foo\nbar\n"
"foo\nbar\n"

Other examples:

>>> toLines ""
[]
>>> toLines "first\nsecond"
["first","second"]
>>> toLines "first\nsecond\n"
["first","second",""]