> Aztec.nr API reference, v6.0.0 (mainnet and testnet). Index: https://docs.aztec.network/aztec-nr-api/v6.0.0/llms.txt

# Primitive type vector

Module: `std`

A dynamically-sized view into a contiguous sequence, `[T]`.

There are two syntactic forms for creating a vector:

- A vector with each element, i.e., `[x, y, z].as_vector()`.
- A repeat expression `[expr; N].as_vector()` where `N` is how many times to repeat `expr` in the vector.

## Implementations

```rust
impl<T> [T]
```

```rust
pub fn len(self) -> u32
```

Returns the length of the vector.

```rust
pub fn push_back(self, elem: T) -> Self
```

Push a new element to the end of the vector, returning a new vector with a length one greater than the original unmodified vector.

```rust
pub fn push_front(self, elem: T) -> Self
```

Push a new element to the front of the vector, returning a new vector with a length one greater than the original unmodified vector.

```rust
pub fn pop_back(self) -> (Self, T)
```

Remove the last element of the vector, returning the popped vector and the element in a tuple

```rust
pub fn pop_front(self) -> (T, Self)
```

Remove the first element of the vector, returning the element and the popped vector in a tuple

```rust
pub fn insert(self, index: u32, elem: T) -> Self
```

Insert an element at a specified index, shifting all elements after it to the right

```rust
pub fn remove(self, index: u32) -> (Self, T)
```

Remove an element at a specified index, shifting all elements after it to the left, returning the altered vector and the removed element

```rust
pub fn append(self, other: Self) -> Self
```

Append each element of the `other` vector to the end of `self`. This returns a new vector and leaves both input vectors unchanged.

```rust
pub fn as_array<let N: u32>(self) -> [T; N]
```

Converts this vector into an array of length N. Panics if the length of this vector is not N.

```rust
pub fn map<U, Env>(self, f: fn[Env](T) -> U) -> [U]
```

Apply a function to each element of the vector, returning a new vector containing the mapped elements.

```rust
pub fn mapi<U, Env>(self, f: fn[Env](u32, T) -> U) -> [U]
```

Apply a function to each element of the vector with its index, returning a new vector containing the mapped elements.

```rust
pub fn for_each<Env>(self, f: fn[Env](T))
```

Apply a function to each element of the vector

```rust
pub fn for_eachi<Env>(self, f: fn[Env](u32, T))
```

Apply a function to each element of the vector with its index

```rust
pub fn fold<U, Env>(self, accumulator: U, f: fn[Env](U, T) -> U) -> U
```

Apply a function to each element of the vector and an accumulator value, returning the final accumulated value. This function is also sometimes called `foldl`, `fold_left`, `reduce`, or `inject`.

```rust
pub fn reduce<Env>(self, f: fn[Env](T, T) -> T) -> T
```

Apply a function to each element of the vector and an accumulator value, returning the final accumulated value. Unlike fold, reduce uses the first element of the given vector as its starting accumulator value.

```rust
pub fn filter<Env>(self, predicate: fn[Env](T) -> bool) -> Self
```

Returns a new vector containing only elements for which the given predicate returns true.

```rust
pub fn join(self, separator: T) -> T
where
    T: Append
```

Flatten each element in the vector into one value, separated by `separator`.

```rust
pub fn all<Env>(self, predicate: fn[Env](T) -> bool) -> bool
```

Returns true if all elements in the vector satisfy the predicate

```rust
pub fn any<Env>(self, predicate: fn[Env](T) -> bool) -> bool
```

Returns true if any element in the vector satisfies the predicate
