holey-format-1.0.0: Combinator-based type-safe formatting (like printf() or FORMAT)

PortabilityGHC
Stabilityexperimental
Maintainerchrisdone@gmail.com
Safe HaskellNone

Text.Format

Contents

Description

Combinator-based type-safe formatting (like printf() or FORMAT) for Text.

Example:

>>> formatPerson =
>>> print (now "Person's name is " . ident . text . now ", age is " . hex . now "\n")
>>> "Dave"
>>> "Jones"
>>> 35

Synopsis

Holey generators

now :: Monoid m => m -> Format m a aSource

Append something to the output stream now.

later :: Monoid m => (a -> m) -> Format m b (a -> b)Source

Append something to the output stream, taking the value as an argument to a formatting function later.

wrap :: (m -> r) -> Wrap r m a tSource

Wrap the whole result in a function.

run :: Monoid f => Format f f a -> aSource

Run the formatter.

ident :: Monoid m => ((m -> r) -> b) -> (m -> r) -> m -> bSource

Identity on later.

Renderers

format :: Format Builder Text a -> aSource

Run the formatter and at the end extract a lazy Text from the Builder.

builder :: Format Builder Builder a -> aSource

Run the formatter producing a Builder.

print :: Format Builder (IO ()) a -> aSource

Run the formatter and print out the text to stdout.

hprint :: Handle -> Format Builder (IO ()) a -> aSource

Run the formatter and put the output onto the given Handle.

General

build :: Buildable a => Build aSource

Include a buildable in the output stream.

text :: Build TextSource

Output a builder.

stext :: Build TextSource

Output a builder.

Integers

hex :: Build IntegerSource

Render an integer using hexadecimal notation. (No leading 0x is added.) hex :: Build Integer

Floats

expt :: Real a => Int -> Build aSource

Render a floating point number using scientific/engineering notation (e.g. 2.3e123), with the given number of decimal places.

fixed :: Real a => Int -> Build aSource

Render a floating point number using normal notation, with the given number of decimal places.

prec :: Real a => Int -> Build aSource

Render a floating point number, with the given number of digits of precision. Uses decimal notation for values between 0.1 and 9,999,999, and scientific notation otherwise.

shortest :: Real a => Build aSource

Render a floating point number using the smallest number of digits that correctly represent it.

Padding

left :: Buildable a => Int -> Char -> Build aSource

Pad the left hand side of a string until it reaches k characters wide, if necessary filling with character c.

right :: Buildable a => Int -> Char -> Build aSource

Pad the right hand side of a string until it reaches k characters wide, if necessary filling with character c.