jjant / elm-printf / Printf

This package provides a type-safe implementation of the famous printf function.

printf : ((a -> a) -> b) -> b

The printf function, takes a format and returns the appropiate type.

  printf (c "Hey") == "Hey"

  printf s "Some string" == "Some string"

Format

c : String -> (String -> a) -> a

The constant format. Takes a string which printf prints as is. printf (c "Something...") == "Something..."

s : (String -> a) -> String -> a

The String format. Passing it to printf means you expect a String.

  printf s "Hey" == "Hey"

i : (String -> a) -> Basics.Int -> a

The Int format. Passing it to printf means you expect an Int

  printf i 23 == "23"

f : Basics.Int -> (String -> a) -> Basics.Float -> a

The Float format. Passing it to printf means you expect a Float. Takes an argument being the number of decimals to show.

  printf (f 5) 1.0000123 == "1.00001"

Combining formats

ap : ((String -> b) -> a) -> ((String -> a) -> c) -> (String -> b) -> c

Combine two formats.

  printf (c "Some" |> ap (c " string")) == "Some string"

  printf (c "My name is " |> ap s) "Jon" == "My name is Jon"