Standard library
Lists
List helpers: length, access, sum, and sort.
Introduction
List helpers: length, access, sum, and sort. Import std/list to bind the module as list. Call free functions as list.name(...). Struct methods use a receiver value.
/ std/list
This page is the package reference for std/list. Private helpers used only by co-located tests are not listed.
Functions
Free functions on list. Each function has a short description, an example, then parameters and return shape.
len
Returns the length of a list. Call form: list.len(xs).
/ std/list
$ n = list.len([1, 2, 3])
Parameters: xs: list value. Returns: Integer length.
is_empty
Reports whether a list is empty. Call form: list.is_empty(xs).
/ std/list
$ empty = list.is_empty([])
Parameters: xs: list value. Returns: Boolean.
get
Result-shaped: ok is the element at index i; error is "out of bounds". Call form: list.get(xs, i).
/ std/list
| list.get([10, 20], 0) {
$ v { }
! e { }
}Parameters: xs: list. i: zero-based index. Returns: Result. Ok arm: element. Err arm: "out of bounds".
contains
Reports whether list xs contains value x. Call form: list.contains(xs, x).
/ std/list
$ ok = list.contains([1, 2], 2)
Parameters: xs: list. x: value to find. Returns: Boolean.
sum_ints
Sums a list of integers. Call form: list.sum_ints(xs).
/ std/list
$ n = list.sum_ints([1, 2, 3])
Parameters: xs: list of integers. Returns: Integer sum.
sort_ints
Returns a new list of integers sorted ascending. Call form: list.sort_ints(xs).
/ std/list
$ ys = list.sort_ints([3, 1, 2])
Parameters: xs: list of integers. Returns: Sorted integer list.