# List

{/* Generated from types/std.Rtypes by `just docs-std`. Do not edit this file. */}

Functions over R lists, typed `list[T]`, and over [Arrays](/type-checking/arrays.md). Each function
also takes an `Array<T>` as its collection (the `list`, `first` or `lists` argument) and then
returns an Array where it would return a list, so `List.map([1, 2, 3], \(x) x * 2)` is the
`Array<double>` `[2, 4, 6]`. An item argument does not count, so `List.append(list([1]), [2])` is
the list `list([1], [2])`, and `List.single` and `List.repeat` always return lists. A function
whose result items come from a callback, such as `List.map`, requires them to be Array items (the
[`item` constraint](/reference/type-system.md#constraints)), so `List.map([1, 2], \(x) list(x))` is
a type error.

| Function | Summary |
| --- | --- |
| [`List.from_vector`](#listfrom_vector) | The elements of an atomic vector as a list. |
| [`List.to_vector`](#listto_vector) | The elements of a list as an atomic vector; every element must be a scalar of one type. |
| [`List.len`](#listlen) | The number of elements. |
| [`List.is_empty`](#listis_empty) | Whether the list has no elements. |
| [`List.get`](#listget) | The element at a 1-based position, or `:Err(:OutOfBounds)`. |
| [`List.set`](#listset) | Replaces the element at a position; a position out of range leaves the list unchanged. |
| [`List.update`](#listupdate) | Replaces the element at a position with `f` of it. |
| [`List.append`](#listappend) | Adds an element at the end. |
| [`List.prepend`](#listprepend) | Adds an element at the start. |
| [`List.concat`](#listconcat) | The elements of `first` followed by those of `second`. |
| [`List.single`](#listsingle) | A list of one element. |
| [`List.repeat`](#listrepeat) | A list of `count` copies of `value`. |
| [`List.range`](#listrange) | The integers from `start` up to and including `end`, or an empty list when `end` is smaller. |
| [`List.reverse`](#listreverse) | The elements in reverse order. |
| [`List.join`](#listjoin) | Concatenates a list of lists. |
| [`List.map`](#listmap) | Applies `f` to every element. |
| [`List.map_with_index`](#listmap_with_index) | Applies `f` to every element and its 1-based position. |
| [`List.map2`](#listmap2) | Applies `f` to the elements of two lists pairwise, stopping at the shorter one. |
| [`List.map3`](#listmap3) | Applies `f` to the elements at each position of three lists, up to the shortest one. |
| [`List.map4`](#listmap4) | Applies `f` to the elements at each position of four lists, up to the shortest one. |
| [`List.join_map`](#listjoin_map) | Applies `f`, which returns a list, to every element and concatenates the results. |
| [`List.keep_if`](#listkeep_if) | The elements for which `predicate` is `TRUE`. |
| [`List.keep_if_try`](#listkeep_if_try) | The elements for which `predicate` returns `:Ok(TRUE)`, or the first `:Err` it returns. |
| [`List.drop_if`](#listdrop_if) | The elements for which `predicate` is `FALSE`. |
| [`List.keep_oks`](#listkeep_oks) | Applies `f` to every element and keeps the `:Ok` values. |
| [`List.keep_errs`](#listkeep_errs) | Applies `f` to every element and keeps the `:Err` values. |
| [`List.map_try`](#listmap_try) | Applies `f` to every element and stops at the first `:Err`. |
| [`List.walk`](#listwalk) | Folds from the first element: `f` gets the state and an element and returns the next state. |
| [`List.walk_backwards`](#listwalk_backwards) | Folds from the last element. |
| [`List.walk_until`](#listwalk_until) | Folds until `f` returns `:Break(state)`; `:Continue(state)` goes on. |
| [`List.walk_backwards_until`](#listwalk_backwards_until) | Folds the list from the last element until `f` returns `:Break(state)`. |
| [`List.walk_with_index`](#listwalk_with_index) | Folds the list, passing `f` each element's 1-based position too. |
| [`List.walk_with_index_until`](#listwalk_with_index_until) | Folds the list with positions until `f` returns `:Break(state)`. |
| [`List.walk_from`](#listwalk_from) | Folds the list from a 1-based position onwards. |
| [`List.walk_from_until`](#listwalk_from_until) | Folds the list from a position until `f` returns `:Break(state)`. |
| [`List.walk_try`](#listwalk_try) | Folds the list while `f` returns `:Ok(state)`, stopping at the first `:Err`. |
| [`List.for_each`](#listfor_each) | Calls `f` on each element for its effect, and returns `NULL` invisibly. |
| [`List.for_each_try`](#listfor_each_try) | Calls `f` on each element, stopping at the first `:Err`. |
| [`List.any`](#listany) | Whether `predicate` is `TRUE` for some element. |
| [`List.all`](#listall) | Whether `predicate` is `TRUE` for every element; `TRUE` for an empty list. |
| [`List.contains`](#listcontains) | Whether some element is `identical()` to `value`. |
| [`List.count_if`](#listcount_if) | The number of elements for which `predicate` is `TRUE`. |
| [`List.find_first`](#listfind_first) | The first element for which `predicate` is `TRUE`, or `:Err(:NotFound)`. |
| [`List.find_last`](#listfind_last) | The last element for which `predicate` is `TRUE`, or `:Err(:NotFound)`. |
| [`List.find_first_index`](#listfind_first_index) | The position of the first match, or `:Err(:NotFound)`. |
| [`List.find_last_index`](#listfind_last_index) | The position of the last match, or `:Err(:NotFound)`. |
| [`List.first`](#listfirst) | The first element, or `:Err(:ListWasEmpty)`. |
| [`List.last`](#listlast) | The last element, or `:Err(:ListWasEmpty)`. |
| [`List.take_first`](#listtake_first) | The first `count` elements, or all of them if there are fewer. |
| [`List.take_last`](#listtake_last) | The last `count` elements. |
| [`List.drop_first`](#listdrop_first) | Everything but the first `count` elements. |
| [`List.drop_last`](#listdrop_last) | Everything but the last `count` elements. |
| [`List.drop_at`](#listdrop_at) | Removes the element at a position. |
| [`List.sublist`](#listsublist) | `count` elements starting at position `start`. |
| [`List.split_at`](#listsplit_at) | The first `count` elements as `before` and the rest as `others`. |
| [`List.split_first`](#listsplit_first) | Splits the list around the first element identical to `delimiter`. |
| [`List.split_last`](#listsplit_last) | Splits the list around the last element identical to `delimiter`. |
| [`List.split_on`](#listsplit_on) | The runs of elements between elements identical to `delimiter`. |
| [`List.split_on_list`](#listsplit_on_list) | The runs of elements between occurrences of the sublist `delimiter`. |
| [`List.chunks_of`](#listchunks_of) | Groups of `size` elements; the last group may be shorter. |
| [`List.intersperse`](#listintersperse) | Puts `separator` between every two elements. |
| [`List.sort_with`](#listsort_with) | A stable sort by `compare`, which returns `:LT`, `:EQ` or `:GT`. |
| [`List.sort_asc`](#listsort_asc) | Sorts numbers from smallest to largest. |
| [`List.sort_desc`](#listsort_desc) | Sorts numbers from largest to smallest. |
| [`List.swap`](#listswap) | Exchanges the elements at two positions; an out-of-range position leaves the list unchanged. |
| [`List.replace`](#listreplace) | Replaces the element at a position, returning the new list and the element it replaced. |
| [`List.append_if_ok`](#listappend_if_ok) | Adds an `:Ok` value at the end; an `:Err` leaves the list unchanged. |
| [`List.prepend_if_ok`](#listprepend_if_ok) | Adds an `:Ok` value at the start; an `:Err` leaves the list unchanged. |
| [`List.concat_utf8`](#listconcat_utf8) | Appends the UTF-8 bytes of a string to a list of bytes. |
| [`List.with_capacity`](#listwith_capacity) | An empty list with room for `capacity` elements, so appending that many never copies. |
| [`List.reserve`](#listreserve) | The list with room for `spare` more elements. |
| [`List.release_excess_capacity`](#listrelease_excess_capacity) | The list with no room beyond its elements, which gives back what `List.reserve` or `List.with_capacity` set aside. |
| [`List.sum`](#listsum) | The sum of the elements; `0L` for an empty list. |
| [`List.product`](#listproduct) | The product of the elements; `1L` for an empty list. |
| [`List.min`](#listmin) | The smallest element, or `:Err(:ListWasEmpty)`. |
| [`List.max`](#listmax) | The largest element, or `:Err(:ListWasEmpty)`. |
| [`List.starts_with`](#liststarts_with) | Whether the list begins with the elements of `prefix`. |
| [`List.ends_with`](#listends_with) | Whether the list ends with the elements of `suffix`. |

## `List.from_vector`

### Inline

```r
List.from_vector <- function<T>(vector: T[]) -> list[T]
```

### Comments

```r
#: <T> fn(vector: T[]) -> list[T]
List.from_vector <- function(vector)
```

The elements of an atomic vector as a list.

```r
List.from_vector(c(3L, 1L, 2L))
#> list(3L, 1L, 2L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L115)

## `List.to_vector`

### Inline

```r
List.to_vector <- function<T>(list: list[T]) -> T[]
```

### Comments

```r
#: <T> fn(list: list[T]) -> T[]
List.to_vector <- function(list)
```

The elements of a list as an atomic vector; every element must be a scalar of one type.

```r
List.to_vector(list(3L, 1L, 2L))
#> c(3L, 1L, 2L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L123)

## `List.len`

### Inline

```r
List.len <- function<T>(list: Array<T>) -> integer
List.len <- function<T>(list: list[T]) -> integer
```

### Comments

```r
#: <T> fn(list: Array<T>) -> integer
List.len <- function(list)

#: <T> fn(list: list[T]) -> integer
List.len <- function(list)
```

The number of elements.

```r
List.len(list("a", "b"))
#> 2L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L131)

## `List.is_empty`

### Inline

```r
List.is_empty <- function<T>(list: Array<T>) -> logical
List.is_empty <- function<T>(list: list[T]) -> logical
```

### Comments

```r
#: <T> fn(list: Array<T>) -> logical
List.is_empty <- function(list)

#: <T> fn(list: list[T]) -> logical
List.is_empty <- function(list)
```

Whether the list has no elements.

```r
List.is_empty(list())
#> TRUE
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L140)

## `List.get`

### Inline

```r
List.get <- function<T>(list: Array<T>, index: integer) -> Result<T, :OutOfBounds>
List.get <- function<T>(list: list[T], index: integer) -> Result<T, :OutOfBounds>
```

### Comments

```r
#: <T> fn(list: Array<T>, index: integer) -> Result<T, :OutOfBounds>
List.get <- function(list, index)

#: <T> fn(list: list[T], index: integer) -> Result<T, :OutOfBounds>
List.get <- function(list, index)
```

The element at a 1-based position, or `:Err(:OutOfBounds)`.

```r
List.get(list("a", "b"), 3L)
#> :Err(:OutOfBounds)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L149)

## `List.set`

### Inline

```r
List.set <- function<T>(list: Array<T>, index: integer, value: T) -> Array<T>
List.set <- function<T>(list: list[T], index: integer, value: T) -> list[T]
```

### Comments

```r
#: <T> fn(list: Array<T>, index: integer, value: T) -> Array<T>
List.set <- function(list, index, value)

#: <T> fn(list: list[T], index: integer, value: T) -> list[T]
List.set <- function(list, index, value)
```

Replaces the element at a position; a position out of range leaves the list unchanged.

```r
List.set(list("a", "b"), 2L, "z")
#> list("a", "z")
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L158)

## `List.update`

### Inline

```r
List.update <- function<T>(list: Array<T>, index: integer, f: fn(T) -> T) -> Array<T>
List.update <- function<T>(list: list[T], index: integer, f: fn(T) -> T) -> list[T]
```

### Comments

```r
#: <T> fn(list: Array<T>, index: integer, f: fn(T) -> T) -> Array<T>
List.update <- function(list, index, f)

#: <T> fn(list: list[T], index: integer, f: fn(T) -> T) -> list[T]
List.update <- function(list, index, f)
```

Replaces the element at a position with `f` of it.

```r
List.update(list(1L, 2L), 1L, function(x) x + 10L)
#> list(11L, 2L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L167)

## `List.append`

### Inline

```r
List.append <- function<T>(list: Array<T>, value: T) -> Array<T>
List.append <- function<T>(list: list[T], value: T) -> list[T]
```

### Comments

```r
#: <T> fn(list: Array<T>, value: T) -> Array<T>
List.append <- function(list, value)

#: <T> fn(list: list[T], value: T) -> list[T]
List.append <- function(list, value)
```

Adds an element at the end.

```r
List.append(list(1L, 2L), 3L)
#> list(1L, 2L, 3L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L176)

## `List.prepend`

### Inline

```r
List.prepend <- function<T>(list: Array<T>, value: T) -> Array<T>
List.prepend <- function<T>(list: list[T], value: T) -> list[T]
```

### Comments

```r
#: <T> fn(list: Array<T>, value: T) -> Array<T>
List.prepend <- function(list, value)

#: <T> fn(list: list[T], value: T) -> list[T]
List.prepend <- function(list, value)
```

Adds an element at the start.

```r
List.prepend(list(1L, 2L), 0L)
#> list(0L, 1L, 2L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L185)

## `List.concat`

### Inline

```r
List.concat <- function<T>(first: Array<T>, second: Array<T>) -> Array<T>
List.concat <- function<T>(first: list[T], second: list[T]) -> list[T]
```

### Comments

```r
#: <T> fn(first: Array<T>, second: Array<T>) -> Array<T>
List.concat <- function(first, second)

#: <T> fn(first: list[T], second: list[T]) -> list[T]
List.concat <- function(first, second)
```

The elements of `first` followed by those of `second`.

```r
List.concat(list(1L), list(2L, 3L))
#> list(1L, 2L, 3L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L194)

## `List.single`

### Inline

```r
List.single <- function<T>(value: T) -> list[T]
```

### Comments

```r
#: <T> fn(value: T) -> list[T]
List.single <- function(value)
```

A list of one element.

```r
List.single("only")
#> list("only")
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L203)

## `List.repeat`

### Inline

```r
List.repeat <- function<T>(value: T, count: integer) -> list[T]
```

### Comments

```r
#: <T> fn(value: T, count: integer) -> list[T]
List.repeat <- function(value, count)
```

A list of `count` copies of `value`.

```r
List.repeat("x", 3L)
#> list("x", "x", "x")
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L211)

## `List.range`

### Inline

```r
List.range <- function(start: integer, end: integer) -> list[integer]
```

### Comments

```r
#: fn(start: integer, end: integer) -> list[integer]
List.range <- function(start, end)
```

The integers from `start` up to and including `end`, or an empty list when `end` is smaller.
Unlike R's `:`, it never counts down.

Both `List.range` and `List.repeat` stop with an error when the list would hold more than
2,147,483,647 elements, the longest vector an R integer index reaches.

```r
List.range(2L, 5L)
#> list(2L, 3L, 4L, 5L)
List.range(3L, 1L)
#> list()
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L225)

## `List.reverse`

### Inline

```r
List.reverse <- function<T>(list: Array<T>) -> Array<T>
List.reverse <- function<T>(list: list[T]) -> list[T]
```

### Comments

```r
#: <T> fn(list: Array<T>) -> Array<T>
List.reverse <- function(list)

#: <T> fn(list: list[T]) -> list[T]
List.reverse <- function(list)
```

The elements in reverse order.

```r
List.reverse(list(1L, 2L, 3L))
#> list(3L, 2L, 1L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L233)

## `List.join`

### Inline

```r
List.join <- function<T>(lists: Array<Array<T>>) -> Array<T>
List.join <- function<T>(lists: list[list[T]]) -> list[T]
```

### Comments

```r
#: <T> fn(lists: Array<Array<T>>) -> Array<T>
List.join <- function(lists)

#: <T> fn(lists: list[list[T]]) -> list[T]
List.join <- function(lists)
```

Concatenates a list of lists.

```r
List.join(list(list(1L), list(), list(2L, 3L)))
#> list(1L, 2L, 3L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L242)

## `List.map`

### Inline

```r
List.map <- function<A, B: item>(list: Array<A>, f: fn(A) -> B) -> Array<B>
List.map <- function<A, B>(list: list[A], f: fn(A) -> B) -> list[B]
```

### Comments

```r
#: <A, B: item> fn(list: Array<A>, f: fn(A) -> B) -> Array<B>
List.map <- function(list, f)

#: <A, B> fn(list: list[A], f: fn(A) -> B) -> list[B]
List.map <- function(list, f)
```

Applies `f` to every element.

```r
List.map(list(1L, 2L, 3L), function(x) x * 2L)
#> list(2L, 4L, 6L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L251)

## `List.map_with_index`

### Inline

```r
List.map_with_index <- function<A, B: item>(list: Array<A>, f: fn(A, integer) -> B) -> Array<B>
List.map_with_index <- function<A, B>(list: list[A], f: fn(A, integer) -> B) -> list[B]
```

### Comments

```r
#: <A, B: item> fn(list: Array<A>, f: fn(A, integer) -> B) -> Array<B>
List.map_with_index <- function(list, f)

#: <A, B> fn(list: list[A], f: fn(A, integer) -> B) -> list[B]
List.map_with_index <- function(list, f)
```

Applies `f` to every element and its 1-based position.

```r
List.map_with_index(list("a", "b"), function(x, i) Str.concat(x, Num.to_str(i)))
#> list("a1", "b2")
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L260)

## `List.map2`

### Inline

```r
List.map2 <- function<A, B, C: item>(first: Array<A>, second: Array<B>, f: fn(A, B) -> C) -> Array<C>
List.map2 <- function<A, B, C>(first: list[A], second: list[B], f: fn(A, B) -> C) -> list[C]
```

### Comments

```r
#: <A, B, C: item> fn(first: Array<A>, second: Array<B>, f: fn(A, B) -> C) -> Array<C>
List.map2 <- function(first, second, f)

#: <A, B, C> fn(first: list[A], second: list[B], f: fn(A, B) -> C) -> list[C]
List.map2 <- function(first, second, f)
```

Applies `f` to the elements of two lists pairwise, stopping at the shorter one.

```r
List.map2(list(1L, 2L, 3L), list(10L, 20L), function(a, b) a + b)
#> list(11L, 22L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L269)

## `List.map3`

### Inline

```r
List.map3 <- function<A, B, C, D: item>(first: Array<A>, second: Array<B>, third: Array<C>, f: fn(A, B, C) -> D) -> Array<D>
List.map3 <- function<A, B, C, D>(first: list[A], second: list[B], third: list[C], f: fn(A, B, C) -> D) -> list[D]
```

### Comments

```r
#: <A, B, C, D: item> fn(first: Array<A>, second: Array<B>, third: Array<C>, f: fn(A, B, C) -> D) -> Array<D>
List.map3 <- function(first, second, third, f)

#: <A, B, C, D> fn(first: list[A], second: list[B], third: list[C], f: fn(A, B, C) -> D) -> list[D]
List.map3 <- function(first, second, third, f)
```

Applies `f` to the elements at each position of three lists, up to the shortest one.

```r
List.map3(list(1L, 2L), list(10L, 20L), list(100L, 200L), function(a, b, c) a + b + c)
#> list(111L, 222L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L278)

## `List.map4`

### Inline

```r
List.map4 <- function<A, B, C, D, E: item>(first: Array<A>, second: Array<B>, third: Array<C>, fourth: Array<D>, f: fn(A, B, C, D) -> E) -> Array<E>
List.map4 <- function<A, B, C, D, E>(first: list[A], second: list[B], third: list[C], fourth: list[D], f: fn(A, B, C, D) -> E) -> list[E]
```

### Comments

```r
#: <A, B, C, D, E: item> fn(first: Array<A>, second: Array<B>, third: Array<C>, fourth: Array<D>, f: fn(A, B, C, D) -> E) -> Array<E>
List.map4 <- function(first, second, third, fourth, f)

#: <A, B, C, D, E> fn(first: list[A], second: list[B], third: list[C], fourth: list[D], f: fn(A, B, C, D) -> E) -> list[E]
List.map4 <- function(first, second, third, fourth, f)
```

Applies `f` to the elements at each position of four lists, up to the shortest one.

```r
List.map4(list(1L), list(2L), list(3L), list(4L), function(a, b, c, d) a * b * c * d)
#> list(24L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L287)

## `List.join_map`

### Inline

```r
List.join_map <- function<A, B>(list: Array<A>, f: fn(A) -> Array<B>) -> Array<B>
List.join_map <- function<A, B>(list: list[A], f: fn(A) -> list[B]) -> list[B]
```

### Comments

```r
#: <A, B> fn(list: Array<A>, f: fn(A) -> Array<B>) -> Array<B>
List.join_map <- function(list, f)

#: <A, B> fn(list: list[A], f: fn(A) -> list[B]) -> list[B]
List.join_map <- function(list, f)
```

Applies `f`, which returns a list, to every element and concatenates the results.

```r
List.join_map(list(1L, 2L), function(x) list(x, x))
#> list(1L, 1L, 2L, 2L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L296)

## `List.keep_if`

### Inline

```r
List.keep_if <- function<T>(list: Array<T>, predicate: fn(T) -> logical) -> Array<T>
List.keep_if <- function<T>(list: list[T], predicate: fn(T) -> logical) -> list[T]
```

### Comments

```r
#: <T> fn(list: Array<T>, predicate: fn(T) -> logical) -> Array<T>
List.keep_if <- function(list, predicate)

#: <T> fn(list: list[T], predicate: fn(T) -> logical) -> list[T]
List.keep_if <- function(list, predicate)
```

The elements for which `predicate` is `TRUE`.

```r
List.keep_if(list(1L, 5L, 2L), function(x) x > 1L)
#> list(5L, 2L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L305)

## `List.keep_if_try`

### Inline

```r
List.keep_if_try <- function<T, E>(list: Array<T>, predicate: fn(T) -> Result<logical, E>) -> Result<Array<T>, E>
List.keep_if_try <- function<T, E>(list: list[T], predicate: fn(T) -> Result<logical, E>) -> Result<list[T], E>
```

### Comments

```r
#: <T, E> fn(list: Array<T>, predicate: fn(T) -> Result<logical, E>) -> Result<Array<T>, E>
List.keep_if_try <- function(list, predicate)

#: <T, E> fn(list: list[T], predicate: fn(T) -> Result<logical, E>) -> Result<list[T], E>
List.keep_if_try <- function(list, predicate)
```

The elements for which `predicate` returns `:Ok(TRUE)`, or the first `:Err` it returns.

```r
List.keep_if_try(list("1", "20", "3"), function(s) Result.map(Str.to_integer(s), function(n) n > 2L))
#> :Ok(list("20", "3"))
List.keep_if_try(list("1", "x"), function(s) Result.map(Str.to_integer(s), function(n) n > 2L))
#> :Err(:InvalidNumStr)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L316)

## `List.drop_if`

### Inline

```r
List.drop_if <- function<T>(list: Array<T>, predicate: fn(T) -> logical) -> Array<T>
List.drop_if <- function<T>(list: list[T], predicate: fn(T) -> logical) -> list[T]
```

### Comments

```r
#: <T> fn(list: Array<T>, predicate: fn(T) -> logical) -> Array<T>
List.drop_if <- function(list, predicate)

#: <T> fn(list: list[T], predicate: fn(T) -> logical) -> list[T]
List.drop_if <- function(list, predicate)
```

The elements for which `predicate` is `FALSE`.

```r
List.drop_if(list(1L, 5L, 2L), function(x) x > 1L)
#> list(1L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L325)

## `List.keep_oks`

### Inline

```r
List.keep_oks <- function<A, B: item, E>(list: Array<A>, f: fn(A) -> Result<B, E>) -> Array<B>
List.keep_oks <- function<A, B, E>(list: list[A], f: fn(A) -> Result<B, E>) -> list[B]
```

### Comments

```r
#: <A, B: item, E> fn(list: Array<A>, f: fn(A) -> Result<B, E>) -> Array<B>
List.keep_oks <- function(list, f)

#: <A, B, E> fn(list: list[A], f: fn(A) -> Result<B, E>) -> list[B]
List.keep_oks <- function(list, f)
```

Applies `f` to every element and keeps the `:Ok` values.

```r
List.keep_oks(list("1", "x", "3"), Str.to_integer)
#> list(1L, 3L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L334)

## `List.keep_errs`

### Inline

```r
List.keep_errs <- function<A, B, E: item>(list: Array<A>, f: fn(A) -> Result<B, E>) -> Array<E>
List.keep_errs <- function<A, B, E>(list: list[A], f: fn(A) -> Result<B, E>) -> list[E]
```

### Comments

```r
#: <A, B, E: item> fn(list: Array<A>, f: fn(A) -> Result<B, E>) -> Array<E>
List.keep_errs <- function(list, f)

#: <A, B, E> fn(list: list[A], f: fn(A) -> Result<B, E>) -> list[E]
List.keep_errs <- function(list, f)
```

Applies `f` to every element and keeps the `:Err` values.

```r
List.keep_errs(list("1", "x"), Str.to_integer)
#> list(:InvalidNumStr)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L343)

## `List.map_try`

### Inline

```r
List.map_try <- function<A, B: item, E>(list: Array<A>, f: fn(A) -> Result<B, E>) -> Result<Array<B>, E>
List.map_try <- function<A, B, E>(list: list[A], f: fn(A) -> Result<B, E>) -> Result<list[B], E>
```

### Comments

```r
#: <A, B: item, E> fn(list: Array<A>, f: fn(A) -> Result<B, E>) -> Result<Array<B>, E>
List.map_try <- function(list, f)

#: <A, B, E> fn(list: list[A], f: fn(A) -> Result<B, E>) -> Result<list[B], E>
List.map_try <- function(list, f)
```

Applies `f` to every element and stops at the first `:Err`.

```r
List.map_try(list("1", "2"), Str.to_integer)
#> :Ok(list(1L, 2L))
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L352)

## `List.walk`

### Inline

```r
List.walk <- function<T, S>(list: Array<T>, state: S, f: fn(S, T) -> S) -> S
List.walk <- function<T, S>(list: list[T], state: S, f: fn(S, T) -> S) -> S
```

### Comments

```r
#: <T, S> fn(list: Array<T>, state: S, f: fn(S, T) -> S) -> S
List.walk <- function(list, state, f)

#: <T, S> fn(list: list[T], state: S, f: fn(S, T) -> S) -> S
List.walk <- function(list, state, f)
```

Folds from the first element: `f` gets the state and an element and returns the next state.

```r
List.walk(list(1L, 2L, 3L), 0L, function(total, x) total + x)
#> 6L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L361)

## `List.walk_backwards`

### Inline

```r
List.walk_backwards <- function<T, S>(list: Array<T>, state: S, f: fn(S, T) -> S) -> S
List.walk_backwards <- function<T, S>(list: list[T], state: S, f: fn(S, T) -> S) -> S
```

### Comments

```r
#: <T, S> fn(list: Array<T>, state: S, f: fn(S, T) -> S) -> S
List.walk_backwards <- function(list, state, f)

#: <T, S> fn(list: list[T], state: S, f: fn(S, T) -> S) -> S
List.walk_backwards <- function(list, state, f)
```

Folds from the last element.

```r
List.walk_backwards(list("a", "b", "c"), "", function(text, x) Str.concat(text, x))
#> "cba"
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L370)

## `List.walk_until`

### Inline

```r
List.walk_until <- function<T, S>(list: Array<T>, state: S, f: fn(S, T) -> :Continue(S) | :Break(S)) -> S
List.walk_until <- function<T, S>(list: list[T], state: S, f: fn(S, T) -> :Continue(S) | :Break(S)) -> S
```

### Comments

```r
#: <T, S> fn(list: Array<T>, state: S, f: fn(S, T) -> :Continue(S) | :Break(S)) -> S
List.walk_until <- function(list, state, f)

#: <T, S> fn(list: list[T], state: S, f: fn(S, T) -> :Continue(S) | :Break(S)) -> S
List.walk_until <- function(list, state, f)
```

Folds until `f` returns `:Break(state)`; `:Continue(state)` goes on.

```r
List.walk_until(list(1L, 2L, 3L, 4L), 0L, function(total, x) if (total >= 3L) :Break(total) else :Continue(total + x))
#> 3L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L379)

## `List.walk_backwards_until`

### Inline

```r
List.walk_backwards_until <- function<T, S>(list: Array<T>, state: S, f: fn(S, T) -> :Continue(S) | :Break(S)) -> S
List.walk_backwards_until <- function<T, S>(list: list[T], state: S, f: fn(S, T) -> :Continue(S) | :Break(S)) -> S
```

### Comments

```r
#: <T, S> fn(list: Array<T>, state: S, f: fn(S, T) -> :Continue(S) | :Break(S)) -> S
List.walk_backwards_until <- function(list, state, f)

#: <T, S> fn(list: list[T], state: S, f: fn(S, T) -> :Continue(S) | :Break(S)) -> S
List.walk_backwards_until <- function(list, state, f)
```

Folds the list from the last element until `f` returns `:Break(state)`.

```r
List.walk_backwards_until(list(1L, 5L, 2L, 3L), 0L, function(total, x) if (x > 4L) :Break(total) else :Continue(total + x))
#> 5L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L388)

## `List.walk_with_index`

### Inline

```r
List.walk_with_index <- function<T, S>(list: Array<T>, state: S, f: fn(S, T, integer) -> S) -> S
List.walk_with_index <- function<T, S>(list: list[T], state: S, f: fn(S, T, integer) -> S) -> S
```

### Comments

```r
#: <T, S> fn(list: Array<T>, state: S, f: fn(S, T, integer) -> S) -> S
List.walk_with_index <- function(list, state, f)

#: <T, S> fn(list: list[T], state: S, f: fn(S, T, integer) -> S) -> S
List.walk_with_index <- function(list, state, f)
```

Folds the list, passing `f` each element's 1-based position too.

```r
List.walk_with_index(list(10L, 20L, 30L), 0L, function(total, x, i) total + x * i)
#> 140L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L397)

## `List.walk_with_index_until`

### Inline

```r
List.walk_with_index_until <- function<T, S>(list: Array<T>, state: S, f: fn(S, T, integer) -> :Continue(S) | :Break(S)) -> S
List.walk_with_index_until <- function<T, S>(list: list[T], state: S, f: fn(S, T, integer) -> :Continue(S) | :Break(S)) -> S
```

### Comments

```r
#: <T, S> fn(list: Array<T>, state: S, f: fn(S, T, integer) -> :Continue(S) | :Break(S)) -> S
List.walk_with_index_until <- function(list, state, f)

#: <T, S> fn(list: list[T], state: S, f: fn(S, T, integer) -> :Continue(S) | :Break(S)) -> S
List.walk_with_index_until <- function(list, state, f)
```

Folds the list with positions until `f` returns `:Break(state)`.

```r
List.walk_with_index_until(list("a", "b", "c"), "", function(seen, x, i) if (i > 2L) :Break(seen) else :Continue(Str.concat(seen, x)))
#> "ab"
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L406)

## `List.walk_from`

### Inline

```r
List.walk_from <- function<T, S>(list: Array<T>, index: integer, state: S, f: fn(S, T) -> S) -> S
List.walk_from <- function<T, S>(list: list[T], index: integer, state: S, f: fn(S, T) -> S) -> S
```

### Comments

```r
#: <T, S> fn(list: Array<T>, index: integer, state: S, f: fn(S, T) -> S) -> S
List.walk_from <- function(list, index, state, f)

#: <T, S> fn(list: list[T], index: integer, state: S, f: fn(S, T) -> S) -> S
List.walk_from <- function(list, index, state, f)
```

Folds the list from a 1-based position onwards.

```r
List.walk_from(list(1L, 2L, 3L, 4L), 3L, 0L, function(total, x) total + x)
#> 7L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L415)

## `List.walk_from_until`

### Inline

```r
List.walk_from_until <- function<T, S>(list: Array<T>, index: integer, state: S, f: fn(S, T) -> :Continue(S) | :Break(S)) -> S
List.walk_from_until <- function<T, S>(list: list[T], index: integer, state: S, f: fn(S, T) -> :Continue(S) | :Break(S)) -> S
```

### Comments

```r
#: <T, S> fn(list: Array<T>, index: integer, state: S, f: fn(S, T) -> :Continue(S) | :Break(S)) -> S
List.walk_from_until <- function(list, index, state, f)

#: <T, S> fn(list: list[T], index: integer, state: S, f: fn(S, T) -> :Continue(S) | :Break(S)) -> S
List.walk_from_until <- function(list, index, state, f)
```

Folds the list from a position until `f` returns `:Break(state)`.

```r
List.walk_from_until(list(1L, 2L, 3L, 4L), 2L, 0L, function(total, x) if (total >= 5L) :Break(total) else :Continue(total + x))
#> 5L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L424)

## `List.walk_try`

### Inline

```r
List.walk_try <- function<T, S, E>(list: Array<T>, state: S, f: fn(S, T) -> Result<S, E>) -> Result<S, E>
List.walk_try <- function<T, S, E>(list: list[T], state: S, f: fn(S, T) -> Result<S, E>) -> Result<S, E>
```

### Comments

```r
#: <T, S, E> fn(list: Array<T>, state: S, f: fn(S, T) -> Result<S, E>) -> Result<S, E>
List.walk_try <- function(list, state, f)

#: <T, S, E> fn(list: list[T], state: S, f: fn(S, T) -> Result<S, E>) -> Result<S, E>
List.walk_try <- function(list, state, f)
```

Folds the list while `f` returns `:Ok(state)`, stopping at the first `:Err`.

```r
List.walk_try(list("1", "2", "x"), 0L, function(total, s) Result.map(Str.to_integer(s), function(n) total + n))
#> :Err(:InvalidNumStr)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L433)

## `List.for_each`

### Inline

```r
List.for_each <- function<T>(list: Array<T>, f: fn(T) -> Any) -> NULL
List.for_each <- function<T>(list: list[T], f: fn(T) -> Any) -> NULL
```

### Comments

```r
#: <T> fn(list: Array<T>, f: fn(T) -> Any) -> NULL
List.for_each <- function(list, f)

#: <T> fn(list: list[T], f: fn(T) -> Any) -> NULL
List.for_each <- function(list, f)
```

Calls `f` on each element for its effect, and returns `NULL` invisibly.

```r
List.for_each(list("a", "b"), function(x) cat(x, "\n"))
#> a
#> b
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L443)

## `List.for_each_try`

### Inline

```r
List.for_each_try <- function<T, E>(list: Array<T>, f: fn(T) -> Result<Any, E>) -> Result<NULL, E>
List.for_each_try <- function<T, E>(list: list[T], f: fn(T) -> Result<Any, E>) -> Result<NULL, E>
```

### Comments

```r
#: <T, E> fn(list: Array<T>, f: fn(T) -> Result<Any, E>) -> Result<NULL, E>
List.for_each_try <- function(list, f)

#: <T, E> fn(list: list[T], f: fn(T) -> Result<Any, E>) -> Result<NULL, E>
List.for_each_try <- function(list, f)
```

Calls `f` on each element, stopping at the first `:Err`.

```r
List.for_each_try(list(1L, -2L, 3L), function(x) if (x < 0L) :Err(:Negative(x)) else :Ok(NULL))
#> :Err(:Negative(-2L))
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L452)

## `List.any`

### Inline

```r
List.any <- function<T>(list: Array<T>, predicate: fn(T) -> logical) -> logical
List.any <- function<T>(list: list[T], predicate: fn(T) -> logical) -> logical
```

### Comments

```r
#: <T> fn(list: Array<T>, predicate: fn(T) -> logical) -> logical
List.any <- function(list, predicate)

#: <T> fn(list: list[T], predicate: fn(T) -> logical) -> logical
List.any <- function(list, predicate)
```

Whether `predicate` is `TRUE` for some element.

```r
List.any(list(1L, 5L), function(x) x > 4L)
#> TRUE
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L461)

## `List.all`

### Inline

```r
List.all <- function<T>(list: Array<T>, predicate: fn(T) -> logical) -> logical
List.all <- function<T>(list: list[T], predicate: fn(T) -> logical) -> logical
```

### Comments

```r
#: <T> fn(list: Array<T>, predicate: fn(T) -> logical) -> logical
List.all <- function(list, predicate)

#: <T> fn(list: list[T], predicate: fn(T) -> logical) -> logical
List.all <- function(list, predicate)
```

Whether `predicate` is `TRUE` for every element; `TRUE` for an empty list.

```r
List.all(list(1L, 5L), function(x) x > 4L)
#> FALSE
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L470)

## `List.contains`

### Inline

```r
List.contains <- function<T>(list: Array<T>, value: T) -> logical
List.contains <- function<T>(list: list[T], value: T) -> logical
```

### Comments

```r
#: <T> fn(list: Array<T>, value: T) -> logical
List.contains <- function(list, value)

#: <T> fn(list: list[T], value: T) -> logical
List.contains <- function(list, value)
```

Whether some element is `identical()` to `value`.

```r
List.contains(list("a", "b"), "b")
#> TRUE
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L479)

## `List.count_if`

### Inline

```r
List.count_if <- function<T>(list: Array<T>, predicate: fn(T) -> logical) -> integer
List.count_if <- function<T>(list: list[T], predicate: fn(T) -> logical) -> integer
```

### Comments

```r
#: <T> fn(list: Array<T>, predicate: fn(T) -> logical) -> integer
List.count_if <- function(list, predicate)

#: <T> fn(list: list[T], predicate: fn(T) -> logical) -> integer
List.count_if <- function(list, predicate)
```

The number of elements for which `predicate` is `TRUE`.

```r
List.count_if(list(1L, 5L, 7L), function(x) x > 4L)
#> 2L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L488)

## `List.find_first`

### Inline

```r
List.find_first <- function<T>(list: Array<T>, predicate: fn(T) -> logical) -> Result<T, :NotFound>
List.find_first <- function<T>(list: list[T], predicate: fn(T) -> logical) -> Result<T, :NotFound>
```

### Comments

```r
#: <T> fn(list: Array<T>, predicate: fn(T) -> logical) -> Result<T, :NotFound>
List.find_first <- function(list, predicate)

#: <T> fn(list: list[T], predicate: fn(T) -> logical) -> Result<T, :NotFound>
List.find_first <- function(list, predicate)
```

The first element for which `predicate` is `TRUE`, or `:Err(:NotFound)`.

```r
List.find_first(list(1L, 5L, 7L), function(x) x > 4L)
#> :Ok(5L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L497)

## `List.find_last`

### Inline

```r
List.find_last <- function<T>(list: Array<T>, predicate: fn(T) -> logical) -> Result<T, :NotFound>
List.find_last <- function<T>(list: list[T], predicate: fn(T) -> logical) -> Result<T, :NotFound>
```

### Comments

```r
#: <T> fn(list: Array<T>, predicate: fn(T) -> logical) -> Result<T, :NotFound>
List.find_last <- function(list, predicate)

#: <T> fn(list: list[T], predicate: fn(T) -> logical) -> Result<T, :NotFound>
List.find_last <- function(list, predicate)
```

The last element for which `predicate` is `TRUE`, or `:Err(:NotFound)`.

```r
List.find_last(list(1L, 5L, 7L), function(x) x > 4L)
#> :Ok(7L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L506)

## `List.find_first_index`

### Inline

```r
List.find_first_index <- function<T>(list: Array<T>, predicate: fn(T) -> logical) -> Result<integer, :NotFound>
List.find_first_index <- function<T>(list: list[T], predicate: fn(T) -> logical) -> Result<integer, :NotFound>
```

### Comments

```r
#: <T> fn(list: Array<T>, predicate: fn(T) -> logical) -> Result<integer, :NotFound>
List.find_first_index <- function(list, predicate)

#: <T> fn(list: list[T], predicate: fn(T) -> logical) -> Result<integer, :NotFound>
List.find_first_index <- function(list, predicate)
```

The position of the first match, or `:Err(:NotFound)`.

```r
List.find_first_index(list(1L, 5L, 7L), function(x) x > 4L)
#> :Ok(2L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L515)

## `List.find_last_index`

### Inline

```r
List.find_last_index <- function<T>(list: Array<T>, predicate: fn(T) -> logical) -> Result<integer, :NotFound>
List.find_last_index <- function<T>(list: list[T], predicate: fn(T) -> logical) -> Result<integer, :NotFound>
```

### Comments

```r
#: <T> fn(list: Array<T>, predicate: fn(T) -> logical) -> Result<integer, :NotFound>
List.find_last_index <- function(list, predicate)

#: <T> fn(list: list[T], predicate: fn(T) -> logical) -> Result<integer, :NotFound>
List.find_last_index <- function(list, predicate)
```

The position of the last match, or `:Err(:NotFound)`.

```r
List.find_last_index(list(1L, 5L, 7L), function(x) x > 9L)
#> :Err(:NotFound)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L524)

## `List.first`

### Inline

```r
List.first <- function<T>(list: Array<T>) -> Result<T, :ListWasEmpty>
List.first <- function<T>(list: list[T]) -> Result<T, :ListWasEmpty>
```

### Comments

```r
#: <T> fn(list: Array<T>) -> Result<T, :ListWasEmpty>
List.first <- function(list)

#: <T> fn(list: list[T]) -> Result<T, :ListWasEmpty>
List.first <- function(list)
```

The first element, or `:Err(:ListWasEmpty)`.

```r
List.first(list("a", "b"))
#> :Ok("a")
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L533)

## `List.last`

### Inline

```r
List.last <- function<T>(list: Array<T>) -> Result<T, :ListWasEmpty>
List.last <- function<T>(list: list[T]) -> Result<T, :ListWasEmpty>
```

### Comments

```r
#: <T> fn(list: Array<T>) -> Result<T, :ListWasEmpty>
List.last <- function(list)

#: <T> fn(list: list[T]) -> Result<T, :ListWasEmpty>
List.last <- function(list)
```

The last element, or `:Err(:ListWasEmpty)`.

```r
List.last(list())
#> :Err(:ListWasEmpty)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L542)

## `List.take_first`

### Inline

```r
List.take_first <- function<T>(list: Array<T>, count: integer) -> Array<T>
List.take_first <- function<T>(list: list[T], count: integer) -> list[T]
```

### Comments

```r
#: <T> fn(list: Array<T>, count: integer) -> Array<T>
List.take_first <- function(list, count)

#: <T> fn(list: list[T], count: integer) -> list[T]
List.take_first <- function(list, count)
```

The first `count` elements, or all of them if there are fewer.

```r
List.take_first(list(1L, 2L, 3L), 2L)
#> list(1L, 2L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L551)

## `List.take_last`

### Inline

```r
List.take_last <- function<T>(list: Array<T>, count: integer) -> Array<T>
List.take_last <- function<T>(list: list[T], count: integer) -> list[T]
```

### Comments

```r
#: <T> fn(list: Array<T>, count: integer) -> Array<T>
List.take_last <- function(list, count)

#: <T> fn(list: list[T], count: integer) -> list[T]
List.take_last <- function(list, count)
```

The last `count` elements.

```r
List.take_last(list(1L, 2L, 3L), 2L)
#> list(2L, 3L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L560)

## `List.drop_first`

### Inline

```r
List.drop_first <- function<T>(list: Array<T>, count: integer) -> Array<T>
List.drop_first <- function<T>(list: list[T], count: integer) -> list[T]
```

### Comments

```r
#: <T> fn(list: Array<T>, count: integer) -> Array<T>
List.drop_first <- function(list, count)

#: <T> fn(list: list[T], count: integer) -> list[T]
List.drop_first <- function(list, count)
```

Everything but the first `count` elements.

```r
List.drop_first(list(1L, 2L, 3L), 2L)
#> list(3L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L569)

## `List.drop_last`

### Inline

```r
List.drop_last <- function<T>(list: Array<T>, count: integer) -> Array<T>
List.drop_last <- function<T>(list: list[T], count: integer) -> list[T]
```

### Comments

```r
#: <T> fn(list: Array<T>, count: integer) -> Array<T>
List.drop_last <- function(list, count)

#: <T> fn(list: list[T], count: integer) -> list[T]
List.drop_last <- function(list, count)
```

Everything but the last `count` elements.

```r
List.drop_last(list(1L, 2L, 3L), 2L)
#> list(1L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L578)

## `List.drop_at`

### Inline

```r
List.drop_at <- function<T>(list: Array<T>, index: integer) -> Array<T>
List.drop_at <- function<T>(list: list[T], index: integer) -> list[T]
```

### Comments

```r
#: <T> fn(list: Array<T>, index: integer) -> Array<T>
List.drop_at <- function(list, index)

#: <T> fn(list: list[T], index: integer) -> list[T]
List.drop_at <- function(list, index)
```

Removes the element at a position.

```r
List.drop_at(list("a", "b", "c"), 2L)
#> list("a", "c")
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L587)

## `List.sublist`

### Inline

```r
List.sublist <- function<T>(list: Array<T>, start: integer, count: integer) -> Array<T>
List.sublist <- function<T>(list: list[T], start: integer, count: integer) -> list[T]
```

### Comments

```r
#: <T> fn(list: Array<T>, start: integer, count: integer) -> Array<T>
List.sublist <- function(list, start, count)

#: <T> fn(list: list[T], start: integer, count: integer) -> list[T]
List.sublist <- function(list, start, count)
```

`count` elements starting at position `start`.

```r
List.sublist(list(1L, 2L, 3L, 4L), 2L, 2L)
#> list(2L, 3L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L596)

## `List.split_at`

### Inline

```r
List.split_at <- function<T>(list: Array<T>, count: integer) -> Record{before: Array<T>, others: Array<T>}
List.split_at <- function<T>(list: list[T], count: integer) -> Record{before: list[T], others: list[T]}
```

### Comments

```r
#: <T> fn(list: Array<T>, count: integer) -> Record{before: Array<T>, others: Array<T>}
List.split_at <- function(list, count)

#: <T> fn(list: list[T], count: integer) -> Record{before: list[T], others: list[T]}
List.split_at <- function(list, count)
```

The first `count` elements as `before` and the rest as `others`.

```r
List.split_at(list(1L, 2L, 3L), 1L)
#> (before = list(1L), others = list(2L, 3L))
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L605)

## `List.split_first`

### Inline

```r
List.split_first <- function<T>(list: Array<T>, delimiter: T) -> Result<Record{before: Array<T>, after: Array<T>}, :NotFound>
List.split_first <- function<T>(list: list[T], delimiter: T) -> Result<Record{before: list[T], after: list[T]}, :NotFound>
```

### Comments

```r
#: <T> fn(list: Array<T>, delimiter: T) -> Result<Record{before: Array<T>, after: Array<T>}, :NotFound>
List.split_first <- function(list, delimiter)

#: <T> fn(list: list[T], delimiter: T) -> Result<Record{before: list[T], after: list[T]}, :NotFound>
List.split_first <- function(list, delimiter)
```

Splits the list around the first element identical to `delimiter`.

```r
List.split_first(list("a", "-", "b", "-", "c"), "-")
#> :Ok((after = list("b", "-", "c"), before = list("a")))
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L614)

## `List.split_last`

### Inline

```r
List.split_last <- function<T>(list: Array<T>, delimiter: T) -> Result<Record{before: Array<T>, after: Array<T>}, :NotFound>
List.split_last <- function<T>(list: list[T], delimiter: T) -> Result<Record{before: list[T], after: list[T]}, :NotFound>
```

### Comments

```r
#: <T> fn(list: Array<T>, delimiter: T) -> Result<Record{before: Array<T>, after: Array<T>}, :NotFound>
List.split_last <- function(list, delimiter)

#: <T> fn(list: list[T], delimiter: T) -> Result<Record{before: list[T], after: list[T]}, :NotFound>
List.split_last <- function(list, delimiter)
```

Splits the list around the last element identical to `delimiter`.

```r
List.split_last(list("a", "-", "b", "-", "c"), "-")
#> :Ok((after = list("c"), before = list("a", "-", "b")))
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L623)

## `List.split_on`

### Inline

```r
List.split_on <- function<T>(list: Array<T>, delimiter: T) -> Array<Array<T>>
List.split_on <- function<T>(list: list[T], delimiter: T) -> list[list[T]]
```

### Comments

```r
#: <T> fn(list: Array<T>, delimiter: T) -> Array<Array<T>>
List.split_on <- function(list, delimiter)

#: <T> fn(list: list[T], delimiter: T) -> list[list[T]]
List.split_on <- function(list, delimiter)
```

The runs of elements between elements identical to `delimiter`.

```r
List.split_on(list(1L, 0L, 2L, 3L, 0L, 4L), 0L)
#> list(list(1L), list(2L, 3L), list(4L))
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L632)

## `List.split_on_list`

### Inline

```r
List.split_on_list <- function<T>(list: Array<T>, delimiter: Array<T>) -> Array<Array<T>>
List.split_on_list <- function<T>(list: list[T], delimiter: list[T]) -> list[list[T]]
```

### Comments

```r
#: <T> fn(list: Array<T>, delimiter: Array<T>) -> Array<Array<T>>
List.split_on_list <- function(list, delimiter)

#: <T> fn(list: list[T], delimiter: list[T]) -> list[list[T]]
List.split_on_list <- function(list, delimiter)
```

The runs of elements between occurrences of the sublist `delimiter`.

```r
List.split_on_list(list(1L, 0L, 0L, 2L, 0L, 3L), list(0L, 0L))
#> list(list(1L), list(2L, 0L, 3L))
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L641)

## `List.chunks_of`

### Inline

```r
List.chunks_of <- function<T>(list: Array<T>, size: integer) -> Array<Array<T>>
List.chunks_of <- function<T>(list: list[T], size: integer) -> list[list[T]]
```

### Comments

```r
#: <T> fn(list: Array<T>, size: integer) -> Array<Array<T>>
List.chunks_of <- function(list, size)

#: <T> fn(list: list[T], size: integer) -> list[list[T]]
List.chunks_of <- function(list, size)
```

Groups of `size` elements; the last group may be shorter.

```r
List.chunks_of(list(1L, 2L, 3L), 2L)
#> list(list(1L, 2L), list(3L))
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L650)

## `List.intersperse`

### Inline

```r
List.intersperse <- function<T>(list: Array<T>, separator: T) -> Array<T>
List.intersperse <- function<T>(list: list[T], separator: T) -> list[T]
```

### Comments

```r
#: <T> fn(list: Array<T>, separator: T) -> Array<T>
List.intersperse <- function(list, separator)

#: <T> fn(list: list[T], separator: T) -> list[T]
List.intersperse <- function(list, separator)
```

Puts `separator` between every two elements.

```r
List.intersperse(list("a", "b", "c"), "-")
#> list("a", "-", "b", "-", "c")
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L659)

## `List.sort_with`

### Inline

```r
List.sort_with <- function<T>(list: Array<T>, compare: fn(T, T) -> :LT | :EQ | :GT) -> Array<T>
List.sort_with <- function<T>(list: list[T], compare: fn(T, T) -> :LT | :EQ | :GT) -> list[T]
```

### Comments

```r
#: <T> fn(list: Array<T>, compare: fn(T, T) -> :LT | :EQ | :GT) -> Array<T>
List.sort_with <- function(list, compare)

#: <T> fn(list: list[T], compare: fn(T, T) -> :LT | :EQ | :GT) -> list[T]
List.sort_with <- function(list, compare)
```

A stable sort by `compare`, which returns `:LT`, `:EQ` or `:GT`.

```r
List.sort_with(list(3L, 1L, 2L), Num.compare)
#> list(1L, 2L, 3L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L668)

## `List.sort_asc`

### Inline

```r
List.sort_asc <- function<T: scalar numeric>(list: Array<T>) -> Array<T>
List.sort_asc <- function<T: scalar numeric>(list: list[T]) -> list[T]
```

### Comments

```r
#: <T: scalar numeric> fn(list: Array<T>) -> Array<T>
List.sort_asc <- function(list)

#: <T: scalar numeric> fn(list: list[T]) -> list[T]
List.sort_asc <- function(list)
```

Sorts numbers from smallest to largest.

```r
List.sort_asc(list(3L, 1L, 2L))
#> list(1L, 2L, 3L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L677)

## `List.sort_desc`

### Inline

```r
List.sort_desc <- function<T: scalar numeric>(list: Array<T>) -> Array<T>
List.sort_desc <- function<T: scalar numeric>(list: list[T]) -> list[T]
```

### Comments

```r
#: <T: scalar numeric> fn(list: Array<T>) -> Array<T>
List.sort_desc <- function(list)

#: <T: scalar numeric> fn(list: list[T]) -> list[T]
List.sort_desc <- function(list)
```

Sorts numbers from largest to smallest.

```r
List.sort_desc(list(1.5, 3, 2))
#> list(3, 2, 1.5)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L686)

## `List.swap`

### Inline

```r
List.swap <- function<T>(list: Array<T>, first: integer, second: integer) -> Array<T>
List.swap <- function<T>(list: list[T], first: integer, second: integer) -> list[T]
```

### Comments

```r
#: <T> fn(list: Array<T>, first: integer, second: integer) -> Array<T>
List.swap <- function(list, first, second)

#: <T> fn(list: list[T], first: integer, second: integer) -> list[T]
List.swap <- function(list, first, second)
```

Exchanges the elements at two positions; an out-of-range position leaves the list unchanged.

```r
List.swap(list("a", "b", "c"), 1L, 3L)
#> list("c", "b", "a")
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L695)

## `List.replace`

### Inline

```r
List.replace <- function<T>(list: Array<T>, index: integer, value: T) -> Record{list: Array<T>, value: T}
List.replace <- function<T>(list: list[T], index: integer, value: T) -> Record{list: list[T], value: T}
```

### Comments

```r
#: <T> fn(list: Array<T>, index: integer, value: T) -> Record{list: Array<T>, value: T}
List.replace <- function(list, index, value)

#: <T> fn(list: list[T], index: integer, value: T) -> Record{list: list[T], value: T}
List.replace <- function(list, index, value)
```

Replaces the element at a position, returning the new list and the element it replaced.

```r
List.replace(list("a", "b"), 2L, "z")
#> (list = list("a", "z"), value = "b")
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L704)

## `List.append_if_ok`

### Inline

```r
List.append_if_ok <- function<T, E>(list: Array<T>, result: Result<T, E>) -> Array<T>
List.append_if_ok <- function<T, E>(list: list[T], result: Result<T, E>) -> list[T]
```

### Comments

```r
#: <T, E> fn(list: Array<T>, result: Result<T, E>) -> Array<T>
List.append_if_ok <- function(list, result)

#: <T, E> fn(list: list[T], result: Result<T, E>) -> list[T]
List.append_if_ok <- function(list, result)
```

Adds an `:Ok` value at the end; an `:Err` leaves the list unchanged.

```r
List.append_if_ok(list(1L), Str.to_integer("2"))
#> list(1L, 2L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L713)

## `List.prepend_if_ok`

### Inline

```r
List.prepend_if_ok <- function<T, E>(list: Array<T>, result: Result<T, E>) -> Array<T>
List.prepend_if_ok <- function<T, E>(list: list[T], result: Result<T, E>) -> list[T]
```

### Comments

```r
#: <T, E> fn(list: Array<T>, result: Result<T, E>) -> Array<T>
List.prepend_if_ok <- function(list, result)

#: <T, E> fn(list: list[T], result: Result<T, E>) -> list[T]
List.prepend_if_ok <- function(list, result)
```

Adds an `:Ok` value at the start; an `:Err` leaves the list unchanged.

```r
List.prepend_if_ok(list(1L), Str.to_integer("x"))
#> list(1L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L722)

## `List.concat_utf8`

### Inline

```r
List.concat_utf8 <- function(list: Array<integer>, string: character) -> Array<integer>
List.concat_utf8 <- function(list: list[integer], string: character) -> list[integer]
```

### Comments

```r
#: fn(list: Array<integer>, string: character) -> Array<integer>
List.concat_utf8 <- function(list, string)

#: fn(list: list[integer], string: character) -> list[integer]
List.concat_utf8 <- function(list, string)
```

Appends the UTF-8 bytes of a string to a list of bytes.

```r
List.concat_utf8(list(104L), "i")
#> list(104L, 105L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L731)

## `List.with_capacity`

### Inline

```r
List.with_capacity <- function<T>(capacity: integer) -> list[T]
```

### Comments

```r
#: <T> fn(capacity: integer) -> list[T]
List.with_capacity <- function(capacity)
```

An empty list with room for `capacity` elements, so appending that many never copies.

```r
List.len(List.with_capacity(1000L))
#> 0L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L740)

## `List.reserve`

### Inline

```r
List.reserve <- function<T>(list: Array<T>, spare: integer) -> Array<T>
List.reserve <- function<T>(list: list[T], spare: integer) -> list[T]
```

### Comments

```r
#: <T> fn(list: Array<T>, spare: integer) -> Array<T>
List.reserve <- function(list, spare)

#: <T> fn(list: list[T], spare: integer) -> list[T]
List.reserve <- function(list, spare)
```

The list with room for `spare` more elements.

```r
List.reserve(list(1L, 2L), 100L)
#> list(1L, 2L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L748)

## `List.release_excess_capacity`

### Inline

```r
List.release_excess_capacity <- function<T>(list: Array<T>) -> Array<T>
List.release_excess_capacity <- function<T>(list: list[T]) -> list[T]
```

### Comments

```r
#: <T> fn(list: Array<T>) -> Array<T>
List.release_excess_capacity <- function(list)

#: <T> fn(list: list[T]) -> list[T]
List.release_excess_capacity <- function(list)
```

The list with no room beyond its elements, which gives back what `List.reserve` or
`List.with_capacity` set aside.

```r
List.release_excess_capacity(List.reserve(list(1L, 2L), 100L))
#> list(1L, 2L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L758)

## `List.sum`

### Inline

```r
List.sum <- function<T: scalar numeric>(list: Array<T>) -> T
List.sum <- function<T: scalar numeric>(list: list[T]) -> T
```

### Comments

```r
#: <T: scalar numeric> fn(list: Array<T>) -> T
List.sum <- function(list)

#: <T: scalar numeric> fn(list: list[T]) -> T
List.sum <- function(list)
```

The sum of the elements; `0L` for an empty list. An `integer` sum that overflows is an error, so
sum doubles, or fold with `Num.add_checked` to get `:Err(:Overflow)` instead. A `double` sum is
accumulated like R's `sum()`, with more precision than a plain left-to-right fold, so
`List.sum(xs)` and `sum(xs)` give the same number.

```r
List.sum(list(1L, 2L, 3L))
#> 6L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L770)

## `List.product`

### Inline

```r
List.product <- function<T: scalar numeric>(list: Array<T>) -> T
List.product <- function<T: scalar numeric>(list: list[T]) -> T
```

### Comments

```r
#: <T: scalar numeric> fn(list: Array<T>) -> T
List.product <- function(list)

#: <T: scalar numeric> fn(list: list[T]) -> T
List.product <- function(list)
```

The product of the elements; `1L` for an empty list. An `integer` product that overflows is an
error, as for `List.sum`.

```r
List.product(list(2, 2.5))
#> 5
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L780)

## `List.min`

### Inline

```r
List.min <- function<T: scalar numeric>(list: Array<T>) -> Result<T, :ListWasEmpty>
List.min <- function<T: scalar numeric>(list: list[T]) -> Result<T, :ListWasEmpty>
```

### Comments

```r
#: <T: scalar numeric> fn(list: Array<T>) -> Result<T, :ListWasEmpty>
List.min <- function(list)

#: <T: scalar numeric> fn(list: list[T]) -> Result<T, :ListWasEmpty>
List.min <- function(list)
```

The smallest element, or `:Err(:ListWasEmpty)`.

```r
List.min(list(3L, 1L, 2L))
#> :Ok(1L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L789)

## `List.max`

### Inline

```r
List.max <- function<T: scalar numeric>(list: Array<T>) -> Result<T, :ListWasEmpty>
List.max <- function<T: scalar numeric>(list: list[T]) -> Result<T, :ListWasEmpty>
```

### Comments

```r
#: <T: scalar numeric> fn(list: Array<T>) -> Result<T, :ListWasEmpty>
List.max <- function(list)

#: <T: scalar numeric> fn(list: list[T]) -> Result<T, :ListWasEmpty>
List.max <- function(list)
```

The largest element, or `:Err(:ListWasEmpty)`.

```r
List.max(list())
#> :Err(:ListWasEmpty)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L798)

## `List.starts_with`

### Inline

```r
List.starts_with <- function<T>(list: Array<T>, prefix: Array<T>) -> logical
List.starts_with <- function<T>(list: list[T], prefix: list[T]) -> logical
```

### Comments

```r
#: <T> fn(list: Array<T>, prefix: Array<T>) -> logical
List.starts_with <- function(list, prefix)

#: <T> fn(list: list[T], prefix: list[T]) -> logical
List.starts_with <- function(list, prefix)
```

Whether the list begins with the elements of `prefix`.

```r
List.starts_with(list(1L, 2L, 3L), list(1L, 2L))
#> TRUE
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L807)

## `List.ends_with`

### Inline

```r
List.ends_with <- function<T>(list: Array<T>, suffix: Array<T>) -> logical
List.ends_with <- function<T>(list: list[T], suffix: list[T]) -> logical
```

### Comments

```r
#: <T> fn(list: Array<T>, suffix: Array<T>) -> logical
List.ends_with <- function(list, suffix)

#: <T> fn(list: list[T], suffix: list[T]) -> logical
List.ends_with <- function(list, suffix)
```

Whether the list ends with the elements of `suffix`.

```r
List.ends_with(list(1L, 2L, 3L), list(2L))
#> FALSE
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L816)
