Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update array method type signatures in the docs #4178

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions docs/docs/noir/concepts/data_types/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,16 @@ You can create arrays of primitive types or structs. There is not yet support fo

## Methods

For convenience, the STD provides some ready-to-use, common methods for arrays:
For convenience, the STD provides some ready-to-use, common methods for arrays.
Each of these functions are located within the generic impl `impl<T, N> [T; N] {`.
So anywhere `self` appears, it refers to the variable `self: [T; N]`.

### len

Returns the length of an array

```rust
fn len<T, N>(_array: [T; N]) -> comptime Field
fn len(self) -> Field
```

example
Expand All @@ -109,7 +111,7 @@ logic it uses internally is optimized specifically for these values. If you need
sort any type, you should use the function `sort_via` described below.

```rust
fn sort<T, N>(_array: [T; N]) -> [T; N]
fn sort(self) -> [T; N]
```

example
Expand All @@ -127,7 +129,7 @@ fn main() {
Sorts the array with a custom comparison function

```rust
fn sort_via<T, N>(mut a: [T; N], ordering: fn(T, T) -> bool) -> [T; N]
fn sort_via(self, ordering: fn(T, T) -> bool) -> [T; N]
```

example
Expand All @@ -148,7 +150,7 @@ fn main() {
Applies a function to each element of the array, returning a new array containing the mapped elements.

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

example
Expand All @@ -164,7 +166,7 @@ Applies a function to each element of the array, returning the final accumulated
parameter is the initial value.

```rust
fn fold<U>(mut accumulator: U, f: fn(U, T) -> U) -> U
fn fold<U>(self, mut accumulator: U, f: fn(U, T) -> U) -> U
```

This is a left fold, so the given function will be applied to the accumulator and first element of
Expand Down Expand Up @@ -198,7 +200,7 @@ fn main() {
Same as fold, but uses the first element as starting element.

```rust
fn reduce<T, N>(f: fn(T, T) -> T) -> T
fn reduce(self, f: fn(T, T) -> T) -> T
```

example:
Expand All @@ -216,7 +218,7 @@ fn main() {
Returns true if all the elements satisfy the given predicate

```rust
fn all<T, N>(predicate: fn(T) -> bool) -> bool
fn all(self, predicate: fn(T) -> bool) -> bool
```

example:
Expand All @@ -234,7 +236,7 @@ fn main() {
Returns true if any of the elements satisfy the given predicate

```rust
fn any<T, N>(predicate: fn(T) -> bool) -> bool
fn any(self, predicate: fn(T) -> bool) -> bool
```

example:
Expand Down
Loading