Skip to content

Commit

Permalink
chore: Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
spotandjake committed Feb 16, 2025
1 parent 8c8d21a commit 9bc5a58
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions stdlib/array.gr
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ provide let init = (length: Number, fn: Number => a) => {

/**
* Creates a new array where each element is initialized with the `Ok`
* value result of an initializer function. The initializer is called with the
* index of each element. Returns the new array if all calls to the
* result value of an initializer function. The initializer is called with the
* index of each element, and returns the new array if all calls to the
* initializer succeed or the first error otherwise.
*
* @param length: The length of the new array
* @param fn: The initializer function to call with each index, where the value returned will be used to initialize the element
* @param fn: The initializer function to call with each index, where the `Ok` value returned will be used to initialize each element
* @returns `Ok(array)` if all elements were successfully initialized or `Err(error)` if the initializer function returned an error
*
* @throws InvalidArgument(String): When `length` is not an integer
Expand Down Expand Up @@ -169,9 +169,9 @@ provide let tryInit = (length: Number, fn: Number => Result<a, b>) => {
},
Err(e) => {
for (let mut j = 0n; j < i; j += 4n) {
Memory.decRef(WasmI32.load(array, _ARRAY_START_OFFSET + j))
Memory.free(array)
ignore(Memory.decRef(WasmI32.load(array, _ARRAY_START_OFFSET + j)))
}
Memory.free(array)
return Err(e)
},
}
Expand Down
10 changes: 5 additions & 5 deletions stdlib/array.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,17 @@ tryInit :
(length: Number, fn: (Number => Result<a, b>)) => Result<Array<a>, b>
```

Creates a new array of the specified length where each element is
initialized with the result of an initializer function. The initializer
is called with the index of each array element. If the initializer function
returns `Err(_)`, the array creation is stopped and the error is returned.
Creates a new array where each element is initialized with the `Ok`
result value of an initializer function. The initializer is called with the
index of each element, and returns the new array if all calls to the
initializer succeed or the first error otherwise.

Parameters:

|param|type|description|
|-----|----|-----------|
|`length`|`Number`|The length of the new array|
|`fn`|`Number => Result<a, b>`|The initializer function to call with each index, where the value returned will be used to initialize the element|
|`fn`|`Number => Result<a, b>`|The initializer function to call with each index, where the `Ok` value returned will be used to initialize each element|

Returns:

Expand Down

0 comments on commit 9bc5a58

Please sign in to comment.