gliua/decode

Helper functions for decoding Uiua values.

Types

pub type DecodeError {
  DecodeError(expected: String, found: String)
}

Constructors

  • DecodeError(expected: String, found: String)
pub type DecodeErrors =
  List(DecodeError)
pub type Decoder(t) =
  fn(Value) -> Result(t, DecodeErrors)

Functions

pub fn char(value: Value) -> Result(Character, List(DecodeError))

Checks to see if a Value is a character, and returns that character if it is.

pub fn complex(
  value: Value,
) -> Result(#(Float, Float), List(DecodeError))

Checks to see if a Value is a complex number, and returns a touple of #(real, imaginary) if it is.

pub fn float(value: Value) -> Result(Float, List(DecodeError))

Checks to see if a Value is a float, and returns that float if it is.

pub fn int(value: Value) -> Result(Int, List(DecodeError))

Checks to see if a Value is an integer, and returns that integer if it is.

pub fn rows(
  of decoder_type: fn(Value) -> Result(a, List(DecodeError)),
) -> fn(Value) -> Result(List(a), List(DecodeError))

Returns a list of a particular type

pub fn stack_1(
  first decoder: fn(Value) -> Result(a, List(DecodeError)),
) -> fn(List(Value)) -> Result(a, List(DecodeError))

Decodes the first value of a list of values

pub fn stack_2(
  first decoder1: fn(Value) -> Result(a, List(DecodeError)),
  second decoder2: fn(Value) -> Result(b, List(DecodeError)),
) -> fn(List(Value)) -> Result(#(a, b), List(DecodeError))

Decodes the first 2 values of a list of values

pub fn stack_3(
  first decoder1: fn(Value) -> Result(a, List(DecodeError)),
  second decoder2: fn(Value) -> Result(b, List(DecodeError)),
  third decoder3: fn(Value) -> Result(c, List(DecodeError)),
) -> fn(List(Value)) -> Result(#(a, b, c), List(DecodeError))

Decodes the first 3 values of a list of values

pub fn string(value: Value) -> Result(String, List(DecodeError))

Checks to see if a Value is a string, and returns that string if it is.

Search Document