This Commented CUE
demonstrates how to use the built-in function
list.IsSortedStrings
as a field validator to assert that lists of strings are sorted alphabetically.
file.cue
package example
import "list"
sorted: ["A", "B", "C"]
unsorted: ["B", "C", "A"]
sorted: list.IsSortedStrings
unsorted: list.IsSortedStrings // validation failure
TERMINAL
$ cue eval
unsorted: invalid value ["B","C","A"] (does not satisfy list.IsSortedStrings):
./file.cue:6:11
./file.cue:9:11
Related content
- How-to Guide: Using "list.IsSortedStrings" to report if lists of strings are sorted
- How-to Guide: Using "list.IsSorted" as a field validator
- The
list
built-in package