vyrn

std/arrays

8 exports, from std/arrays.vyrn.

Higher-order array helpers such as map, filter and fold, in Vyrn. Applies f to every element, collecting the results into a new array.

Dependencies

The import graph shows the whole library.

Imports
fn all<T>(xs: Array<T>, pred: fn(T) -> Bool) -> Bool

Whether pred holds for every element; true when empty.

fn includes(xs: Array<String>, x: String) -> Bool

Whether xs contains the string x. The parameter is Array<String>, not generic, because a generic Array<T> parameter does not accept a fixed-size array literal.

fn sortWith<T>(xs: Array<T>, cmp: fn(T, T) -> Int64) -> Array<T>

A stable sorted copy, ordered by a comparator: negative puts a before b, positive after, zero keeps arrival order. Insertion sort.

fn sortBy<T>(xs: Array<T>, key: fn(T) -> Int64) -> Array<T>

A stable sorted copy, ascending by an Int64 key. Insertion sort.

Tests

2 test blocks in std/arrays.vyrn. CI runs all of them.

Test names
  • sortWith orders by the comparator, stably
  • sortWith orders across the Int64 limits

Examples

5 programs in examples/ import this module. Each runs as WebAssembly and as a native binary.