glyde/field

The three states a JSON key can be in, which Option cannot say: the key is missing, the key is null, or the key holds a value.

Both directions need all three. Encoding a PATCH, parent_id: null clears a channel’s category and omitting the key leaves the category alone. Decoding, wire.tri_field builds one and model/message keeps it, so “Discord never resolved this” stays apart from “it was deleted”.

Present, not Set, so an unqualified import does not shadow gleam/set.

Types

pub type Field(a) {
  Absent
  Null
  Present(a)
}

Constructors

  • Absent
  • Null
  • Present(a)

Values

pub fn from_option(option: option.Option(a)) -> Field(a)

None becomes Absent, so this cannot spell “clear”.

pub fn is_absent(field: Field(a)) -> Bool
pub fn map(field: Field(a), with fun: fn(a) -> b) -> Field(b)
Search Document