glormat

Functions

pub fn assert_ok(result: Result(String, Nil)) -> String

Assert that result is Ok, returning the contained String. This may be useful in cases where you as the programmer know that formatting will not fail, but the compiler does not.

pub fn debug(
  in format_string: String,
  replace label: String,
  with data: a,
) -> Result(String, Nil)

A wrapper for format that calls string.inspect on data before passing it in.

This allows formatting with non-String data.

pub fn format(
  in format_string: String,
  replace label: String,
  with data: String,
) -> Result(String, Nil)

Replace all instances of "{label}" with data in the input string.

To replace more labels, pipe this function into then or then_debug.

If you want to use format in a pipeline, replace may be more concise.

If the given label isn’t found, this function returns Error(Nil).

Examples

let assert Ok("hello world") =
  format(in: "hello {object}", replace: "object", with: "world")
pub fn replace(
  in format_string: String,
  replace label: String,
  with data: String,
) -> Result(String, Nil)

An alias for format that may lend more readable code.

Examples

let assert Ok("hello world") =
  "hello {object}"
  |> replace("object", with: "world")
pub fn then(
  in result: Result(String, Nil),
  replace label: String,
  with data: String,
) -> Result(String, Nil)

If result is Ok, call format on the contained value, otherwise return the Error.

Examples

let assert Ok("hello world, how are you?") =
  "hello {object}, {question}?"
  |> replace("object", with: "world")
  |> then("question", with: "how are you")
pub fn then_debug(
  in result: Result(String, Nil),
  replace label: String,
  with data: a,
) -> Result(String, Nil)

A wrapper for then that calls string.inspect on data before passing it in. This allows formatting with non-String data.

Search Document