CUE values have a number of methods that we can use to inspect their contents, state, and location. While we saw how to print the full value and its error state, the functions here provide more granular details.
We will be using the following CUE file for the examples in this section.
Path return paths to the value
which can be used with
LookupPath to get the value.
They can be considered inverse functions of each other.
ReferencePath and Dereference
Exists and IsConcrete
When you lookup a value, how do you know if it was found?
That is where
Exists comes in.
IsConcrete can tell you if an atom field has data or is a terminal error.
For lists and structs, it will report true if they exist and not recurse to check subvalues.
When disjunctions and defaults are used…
Validate to check complete values for concreteness.
Kind and IncompleteKind
Kind and IncompleteKind will tell you the underlying type of a value. IncompleteKind is more granular and returns type info regarless of how complete a value is (the names may seem a bit backwards).
You can also switch on the results of both functions.
Values have a number of functions for turning the abstract into the underlying type. You will first want to know what type of value you are dealing with before trying to convert it.
Len will tell you the length of a list or how many bytes are in a bytes.