This module provides an API to deconstruct Noun
s into arbitrary Elm data structures.
You would parse a `[%edit
Ur.Types.Noun -> Maybe a
A Noun
deconstructor.
Deconstructor
run : Deconstructor a -> Ur.Types.Noun -> Maybe a
Executes a Deconstructor
on a Noun
.
runBytes : Deconstructor a -> Bytes -> Maybe a
Executes a deconstructor on a jam
med Noun
.
Deconstructor
scell : Deconstructor a -> Deconstructor b -> Ur.Types.Noun -> Maybe ( a, b )
Extracts a Cell
(pair) of two arbitrary values.
Accepts two arbitrary Deconstructor
s that form a Cell.
list : Deconstructor a -> Ur.Types.Noun -> Maybe (List a)
Extracts a sig-terminated list of arbitrary elements.
The first argument is a Deconstructor
of the elements of the list.
oneOf : List (Deconstructor a) -> Deconstructor a
Try to execute all of the Deconstructor
s in order until one succeeds.
This is especially useful for deconstructing head-tagged unions from Hoon.
const : Deconstructor a -> a -> Ur.Types.Noun -> Maybe ()
Asserts that the value should be exactly equal to the second argument.
The first argument is a Deconstructor
for the given type.
The second argument is the value to compare with.
This is useful to match on term
s when there are multiple possible cases in a head-tagged union.
Deconstructor
map : (a -> b) -> Deconstructor a -> Ur.Types.Noun -> Maybe b
Maps over the result of the deconstructor.
Int
aint : Ur.Types.Noun -> Maybe Basics.Int
Extracts a 32-bit unsigned Int
.
If the Atom
is larger than 32 bits the the behaviour is undefined.
signedInt : Deconstructor Basics.Int
Extracts a 32-bit signed Int
.
If the Atom
is larger than 32 bits the the behaviour is undefined.
bigint : Ur.Types.Noun -> Maybe BigInt
Extracts a BigInt
.
Float
sfloat32 : Ur.Types.Noun -> Maybe Basics.Float
Extracts a 32-bit Float
.
float64 : Ur.Types.Noun -> Maybe Basics.Float
Extracts a 64-bit Float
.
String
scord : Ur.Types.Noun -> Maybe String
Extracts a cord
.
tape : Deconstructor String
Extracts a tape
.
bytes : Ur.Types.Noun -> Maybe Bytes
Extracts the raw Byte
s of an Atom
.
sig : Ur.Types.Noun -> Maybe ()
Asserts the the Atom
should be exactly sig
(~
).
ignore : Deconstructor ()
Ignore any value.
This is useful when you have a value you don't care about. ignore
allows you to just skip the value.
tar : Deconstructor Ur.Types.Noun
Extract the raw Noun
.
Always succeeds.
lazy : (() -> Deconstructor a) -> Ur.Types.Noun -> Maybe a
Maps (applies) a function to all of the values deconstructed.
This is useful when you want to create a data type with extracted values as fields.
debug : (String -> String) -> Deconstructor a -> Ur.Types.Noun -> Maybe a
Debug a deconstructor. If the deconstructor from the second argument fails then the failed nock will be printed to the console.