offstage/dynamic/spec

Types

A common specification type for representing JSON and YAML structures.

pub type Spec {
  String(value: String)
  Integer(value: Int)
  Float(value: Float)
  Boolean(value: Bool)
  Null
  Array(values: List(Spec))
  Object(properties: List(#(String, Spec)))
}

Constructors

  • String(value: String)
  • Integer(value: Int)
  • Float(value: Float)
  • Boolean(value: Bool)
  • Null
  • Array(values: List(Spec))
  • Object(properties: List(#(String, Spec)))

Values

pub fn array(values: List(Spec)) -> Spec

Creates a Spec representing an array of values.

pub fn array_of(
  values: List(a),
  transformer: fn(a) -> Spec,
) -> Spec

Creates a Spec representing an array of transformed values.

pub fn boolean(value: Bool) -> Spec

Creates a Spec representing a boolean value.

pub fn float(value: Float) -> Spec

Creates a Spec representing a float value.

pub fn integer(value: Int) -> Spec

Creates a Spec representing an integer value.

pub fn none_if_empty(list: List(a)) -> option.Option(List(a))

Returns option.None if the list is empty, otherwise returns option.Some with the list.

pub fn null() -> Spec

Creates a Spec representing a null value.

pub fn nullable(
  value: option.Option(a),
  transformer: fn(a) -> Spec,
) -> Spec

Creates a Spec representing a nullable value.

pub fn object(properties: List(#(String, Spec))) -> Spec

Creates a Spec representing an object with the given properties.

pub fn object_of(
  values: List(a),
  transformer: fn(a) -> #(String, Spec),
) -> Spec

Creates a Spec representing an object with transformed properties.

pub fn object_of_tuple(
  values: List(#(String, a)),
  transformer: fn(a) -> Spec,
) -> Spec

Creates a Spec representing an object from a list of key-value tuples, transforming the values.

pub fn omit_null(spec: Spec) -> Spec

Recursively omits Null values from a Spec.

pub fn string(value: String) -> Spec

Creates a Spec representing a string value.

pub fn to_dynamic(spec: Spec) -> dynamic.Dynamic

Converts a Spec to a dynamic value.

pub fn to_json(spec: Spec) -> json.Json

Converts a Spec to a JSON value.

pub fn to_yaml(spec: Spec) -> value.YamlValue

Converts a Spec to a YAML value.

✨ Search Document