# std/arrays

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

## map

`fn`, at line 4.

```vyrn
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.

## filter

`fn`, at line 13.

```vyrn
fn filter<T>(xs: Array<T>, pred: fn(T) -> Bool) -> Array<T>
```

Keeps only the elements for which `pred` returns `true`.

## fold

`fn`, at line 24.

```vyrn
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`.

## any

`fn`, at line 33.

```vyrn
fn any<T>(xs: Array<T>, pred: fn(T) -> Bool) -> Bool
```

Whether `pred` holds for at least one element.

## all

`fn`, at line 43.

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

Whether `pred` holds for every element; true when empty.

## includes

`fn`, at line 55.

```vyrn
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.

## sortWith

`fn`, at line 66.

```vyrn
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.

## sortBy

`fn`, at line 113.

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

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

---

From https://vyrn-lang.github.io/docs/std/arrays.html — generated by `site/export.vyrn` from the Vyrn repository.
