diff --git a/docs/docs/noir/concepts/data_types/arrays.md b/docs/docs/noir/concepts/data_types/arrays.md index 7f275a2d771..a8bd338e736 100644 --- a/docs/docs/noir/concepts/data_types/arrays.md +++ b/docs/docs/noir/concepts/data_types/arrays.md @@ -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] {`. +So anywhere `self` appears, it refers to the variable `self: [T; N]`. ### len Returns the length of an array ```rust -fn len(_array: [T; N]) -> comptime Field +fn len(self) -> Field ``` example @@ -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(_array: [T; N]) -> [T; N] +fn sort(self) -> [T; N] ``` example @@ -127,7 +129,7 @@ fn main() { Sorts the array with a custom comparison function ```rust -fn sort_via(mut a: [T; N], ordering: fn(T, T) -> bool) -> [T; N] +fn sort_via(self, ordering: fn(T, T) -> bool) -> [T; N] ``` example @@ -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(f: fn(T) -> U) -> [U; N] +fn map(self, f: fn(T) -> U) -> [U; N] ``` example @@ -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(mut accumulator: U, f: fn(U, T) -> U) -> U +fn fold(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 @@ -198,7 +200,7 @@ fn main() { Same as fold, but uses the first element as starting element. ```rust -fn reduce(f: fn(T, T) -> T) -> T +fn reduce(self, f: fn(T, T) -> T) -> T ``` example: @@ -216,7 +218,7 @@ fn main() { Returns true if all the elements satisfy the given predicate ```rust -fn all(predicate: fn(T) -> bool) -> bool +fn all(self, predicate: fn(T) -> bool) -> bool ``` example: @@ -234,7 +236,7 @@ fn main() { Returns true if any of the elements satisfy the given predicate ```rust -fn any(predicate: fn(T) -> bool) -> bool +fn any(self, predicate: fn(T) -> bool) -> bool ``` example: