Try Install Learn Blog API Packages GitHub
Pages
core

Search
Entities

Object.Decode

Functions

array
(
input
:
Object
decoder
:
Function(Object, Result(Object.Error, a))
)
:
Result(Object.Error, Array(a))

Decodes the object as an Array using the given decoder.

Object.Decode.array(`["A", "B"]`, Object.Decode.string) == Result::Ok(["a", "b"])
boolean
(
input
:
Object
)
:
Result(Object.Error, Bool)

Decodes the object as a Bool

Object.Decode.boolean(`true`) == Result::Ok(true)
field
(
input
:
Object
key
:
String
decoder
:
Function(Object, Result(Object.Error, a))
)
:
Result(Object.Error, a)

Decodes a field from an object using the given decoder.

Object.Decode.field(
  `{field: "Value"}`, "field", Object.Decode.string) == Result::Ok("Value")
maybe
(
input
:
Object
decoder
:
Function(Object, Result(Object.Error, a))
)
:
Result(Object.Error, Maybe(a))

Decodes the object as a Maybe(a) using the given decoder.

Object.Decode.maybe(`"A"`, Object.Decode.String) == Result::Ok(Maybe::Just("A"))
Object.Decode.maybe(`null`, Object.Decode.String) == Result::Ok(Maybe::Nothing)
number
(
input
:
Object
)
:
Result(Object.Error, Number)

Decodes the object as a Number

Object.Decode.number(`0`) == Result::Ok(0)
string
(
input
:
Object
)
:
Result(Object.Error, String)

Decodes the object as a String

Object.Decode.string(`"A"`) == Result::Ok("A")
time
(
input
:
Object
)
:
Result(Object.Error, Time)

Decodes the object as a Time

Object.Decode.time(`"new Date()"`)