krisajenkins/formatting/2.1.0

NOTE: this package is not compatible with Elm 0.19.1

Formatting

A type-safe string formatting library. It fulfils the need for string-interpolation or a printf function, without sacrificing Elm's runtime guarantees or requiring any language-level changes. It also composes well, to make building up complex formatters easy.

Example:

import Formatting exposing (..)


greeting =
    s "Hello " <> string <> s "!"


print greeting "Kris"


--> "Hello Kris!"
type Format r a

A string formatter. This type holds all the information we need to create a formatting function, wrapped up in a way that makes it easy to compose.

Build one of these up with primitives like s, string and int, join them together with <>, and when you're done, generate the final printing function with print.

(<>) : Format b a -> Format c b -> Format c a

Compose two formatters together.

print : Format String a -> a

Turn your formatter into a function that's just waiting for its arguments.

For example:

order =
    let
        format = s "FREE: " <> int <> s " x " <> string  <> s "!"
    in
        print format 2 "Ice Cream"


--> "FREE: 2 x Ice Cream!"
html : Format (Html msg) a -> a

Convenience function. Like print, but returns an Html.text node as its final result, instead of a String.

s : String -> Format r r

A boilerplate string.

string : Format r (String -> r)

A placeholder for a String argument.

int : Format r (Int -> r)

A placeholder for an Int argument.

float : Format r (Float -> r)

A placeholder for an Float argument.