yum/yaml/builder

Build YAML nodes in Gleam code.

The functions in this module create synthetic Node values. Pass the root node to yum/yaml.from_node when you want to emit it as YAML or use it with the rest of the public YAML API.

import yum/yaml
import yum/yaml/builder

pub fn example() {
  let document =
    builder.mapping([
      #(builder.string("name"), builder.string("yum")),
      #(
        builder.string("commands"),
        builder.sequence([
          builder.string("gleam test"),
          builder.string("gleam format"),
        ]),
      ),
    ])
    |> yaml.from_node()

  let output = yaml.to_string(document)

  assert output ==
"name: yum
commands:
  - gleam test
  - gleam format"
}

Values

pub fn bool(value: Bool) -> node.Node

Builds a YAML boolean node.

pub fn float(value: Float) -> node.Node

Builds a YAML floating-point node.

YAML’s special float values are represented as separate node kinds. Use node.synthetic with node.PosInf, node.NegInf, or node.Nan for those values.

pub fn int(value: Int) -> node.Node

Builds a YAML integer node.

pub fn mapping(
  entries: List(#(node.Node, node.Node)),
) -> node.Node

Builds a YAML mapping node from already-built key/value node pairs.

pub fn null() -> node.Node

Builds a YAML null node.

pub fn sequence(entries: List(node.Node)) -> node.Node

Builds a YAML sequence node from already-built nodes.

pub fn string(value: String) -> node.Node

Builds a YAML string node.

Search Document