gleam/dynamic

Types

Dynamic data is data that we don’t know the type of yet. We likely get data like this from interop with Erlang, or from IO with the outside world.

This module contains code for forming dynamic data, and the gleam/dynamic/decode module contains code for turning dynamic data back into Gleam data with known types. You will likely mostly use the other module in your projects.

The exact runtime representation of dynamic values will depend on the compilation target used.

pub type Dynamic

Values

pub fn array(a: List(Dynamic)) -> Dynamic

Create a dynamic value from a list, converting it to a sequential runtime format rather than the regular list format.

On Erlang this will be a tuple, on JavaScript this wil be an array.

pub fn bit_array(a: BitArray) -> Dynamic

Create a dynamic value from a bit array.

pub fn bool(a: Bool) -> Dynamic

Create a dynamic value from a bool.

pub fn classify(data: Dynamic) -> String

Return a string indicating the type of the dynamic value.

This function may be useful for constructing error messages or logs. If you want to turn dynamic data into well typed data then you want the gleam/dynamic/decode module.

classify(from("Hello"))
// -> "String"
pub fn float(a: Float) -> Dynamic

Create a dynamic value from a float.

pub fn from(a: anything) -> Dynamic

Deprecated: Please use the other functions in the gleam/dynamic module

pub fn int(a: Int) -> Dynamic

Create a dynamic value from an int.

pub fn list(a: List(Dynamic)) -> Dynamic

Create a dynamic value from a list.

pub fn nil() -> Dynamic

A dynamic value representing nothing.

On Erlang this will be the atom nil, on JavaScript this wil be undefined.

pub fn properties(entries: List(#(Dynamic, Dynamic))) -> Dynamic

Create a dynamic value made an unordered series of keys and values, where the keys are unique.

On Erlang this will be a map, on JavaScript this wil be a Gleam dict object.

pub fn string(a: String) -> Dynamic

Create a dynamic value from a string.

On Erlang this will be a binary string rather than a character list.

Search Document
OSZAR »