map fn
std/arrays.vyrn, line 4Used in the guide: Function values and closuresRun it in the playgroundfn map<T, U>(xs: Array<T>, f: fn(T) -> U) -> Array<U>
Applies f to every element, collecting the results into a new array.
Type to search, or try , or .
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.
The import graph shows the whole library.
fn map<T, U>(xs: Array<T>, f: fn(T) -> U) -> Array<U>
Applies f to every element, collecting the results into a new array.
fn filter<T>(xs: Array<T>, pred: fn(T) -> Bool) -> Array<T>
Keeps only the elements for which pred returns true.
fn fold<T, A>(xs: Array<T>, init: A, f: fn(A, T) -> A) -> A
Left fold: threads acc through f for every element, starting from init.
fn any<T>(xs: Array<T>, pred: fn(T) -> Bool) -> Bool
Whether pred holds for at least one element.
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.
2 test blocks in std/arrays.vyrn. CI runs all of them.
5 programs in examples/ import this module. Each runs as WebAssembly and as a native binary.