twister/util

Tiny module containing utility helper functions.

Note

Unless you have a specific use case and no better (already existing) way to solve it, you should prefer other libraries or even your own code.

Values

pub fn at(in: List(a), index index: Int) -> Result(a, Nil)

Get the element at specified index in the provided List, using 0-indexing (element at index 0 is the first element)

If the index given is equal to or larger than the length of the List, return Error(Nil).

If the index is less than zero, return Error(Nil).

Otherwise return Ok(a) - the element at the given index.

Note

This function runs in O(n) where n is the index. This is due to the fact that Gleam Lists are linked-lists, not arrays, so to find a given index it’s necessary to traverse the List until encountering it.

pub fn largest(indexes: List(Int)) -> option.Option(Int)

Given a List of Ints, find the largest element.

If the List is empty, return None.

Note

This function runs in O(n), where n is the length of the list.

Search Document