Skip to content

ard/list

The ard/list module provides a small set of generic helpers for working with Ard lists.

Import it explicitly when needed:

use ard/list

Create a new empty list. The expected type is usually inferred from context.

use ard/list
let nums: [Int] = list::new()

Return a new list containing the elements of a followed by the elements of b.

use ard/list
let combined = list::concat([1, 2, 3], [4, 5])

Return a new list containing elements whose index is greater than or equal to till.

use ard/list
let tail = list::drop([1, 2, 3, 4], 2) // [3, 4]

Return a new list containing only values for which where returns true.

use ard/list
let evens = list::keep([1, 2, 3, 4], fn(n: Int) Bool { n % 2 == 0 })

map(list: [$A], transform: fn($A) $B) [$B]

Section titled “map(list: [$A], transform: fn($A) $B) [$B]”

Transform each element and return the transformed values in order.

use ard/list
let doubled = list::map([1, 2, 3], fn(n: Int) Int { n * 2 })

Return the first matching value, or none if no value matches.

use ard/list
let found = list::find([1, 2, 3], fn(n: Int) Bool { n == 2 })

partition(list: [$T], where: fn($T) Bool) Partition<$T>

Section titled “partition(list: [$T], where: fn($T) Bool) Partition<$T>”

Split a list into matching and non-matching values.

use ard/list
let parts = list::partition([1, 2, 3, 4], fn(n: Int) Bool { n > 2 })
// parts.selected == [3, 4]
// parts.others == [1, 2]

partition_int(list: [Int], where: fn(Int) Bool) IntPartition

Section titled “partition_int(list: [Int], where: fn(Int) Bool) IntPartition”

Specialized Int version of partition.

struct Partition {
selected: [$T],
others: [$T],
}
struct IntPartition {
selected: [Int],
others: [Int],
}