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!"Compose two formatters together.
Turn your formatter into a function that's just waiting for its arguments.
Given this format:
orderFormat =
s "FREE: " <> int <> s " x " <> string <> s "!"...we can either use it immediately:
order : String
order = print orderFormat 2 "Ice Cream"
--> "FREE: 2 x Ice Cream!"...or turn it into an ordinary function to be used later:
orderFormatter : Int -> String -> String
orderFormatter =
print orderFormat
...elsewhere...
order : String
order = orderFormatter 2 "Ice Cream"
--> "FREE: 2 x Ice Cream!"Convenience function. Like print, but returns an Html.text
node as its final result, instead of a String.
A boilerplate string.
A placeholder for a String argument.
A placeholder for an Int argument.
A placeholder for a Float argument.
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,stringandint, join them together with<>, and when you're done, generate the final printing function withprint.