Skip to content

Commit 50cc6b2

Browse files
authored
Update StaticArray & normalize other array's declarations (#104)
1 parent a8bca5a commit 50cc6b2

File tree

3 files changed

+90
-36
lines changed

3 files changed

+90
-36
lines changed

src/stdlib/array.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ arr[0]; // now it works 😊
5353
Copies a region of an array's values over the respective values starting at the target location.
5454

5555
* ```ts
56-
function every(fn: (value: T, index: i32, array: Array<T>) => bool): bool
56+
function every(fn: (value: T, index: i32, self: Array<T>) => bool): bool
5757
```
5858
Calls the specified function with every value of the array until it finds the first value for which the function returns `false`. Returns `true` if all functions returned `true` or the array is empty, otherwise `false`.
5959

@@ -63,17 +63,17 @@ arr[0]; // now it works 😊
6363
Replaces the values of the array from `start` inclusive to `end` exclusive in place with the specified value, returning the array.
6464

6565
* ```ts
66-
function filter(fn: (value: T, index: i32, array: Array<T>) => bool): Array<T>
66+
function filter(fn: (value: T, index: i32, self: Array<T>) => bool): Array<T>
6767
```
6868
Calls the specified function with every value of the array, returning a new array with all values for which the function returned `true`.
6969

7070
* ```ts
71-
function findIndex(fn: (value: T, index: i32, array: Array<T>) => bool): i32
71+
function findIndex(fn: (value: T, index: i32, self: Array<T>) => bool): i32
7272
```
7373
Calls the specified function with every value of the array until it finds the first value for which the function returns `true`, returning its index. Returns `-1` if that's never the case.
7474

7575
* ```ts
76-
function findLastIndex(fn: (value: T, index: i32, self: this) => bool): i32;
76+
function findLastIndex(fn: (value: T, index: i32, self: Array<T>) => bool): i32;
7777
```
7878
Calls the specified function with every value of the array starting at the end until it finds the first value for which the function returns `true`, returning its index. Returns `-1` if that's never the case.
7979

@@ -83,7 +83,7 @@ arr[0]; // now it works 😊
8383
Flattens an array of arrays to a one-dimensional array. `null` entries are ignored.
8484

8585
* ```ts
86-
function forEach(fn: (value: T, index: i32, array: Array<T>) => void): void
86+
function forEach(fn: (value: T, index: i32, self: Array<T>) => void): void
8787
```
8888
Calls the specified function with every value of the array.
8989

@@ -108,7 +108,7 @@ arr[0]; // now it works 😊
108108
Gets the last index where the specified value can be found in the array. Returns `-1` if not found.
109109

110110
* ```ts
111-
function map<U>(fn: (value: T, index: i32, array: Array<T>) => U): Array<U>
111+
function map<U>(fn: (value: T, index: i32, self: Array<T>) => U): Array<U>
112112
```
113113
Calls the specified function with every value of the array, returning a new array of the function's return values.
114114

@@ -124,15 +124,15 @@ arr[0]; // now it works 😊
124124

125125
* ```ts
126126
function reduce<U>(
127-
fn: (acc: U, cur: T, idx: i32, src: Array) => U,
127+
fn: (accumValue: U, currentValue: T, index: i32, self: Array<T>) => U,
128128
initialValue: U
129129
): U
130130
```
131-
Calls the specified reducer function with each value of the array, resulting in a single return value. The respective previous reducer function's return value is remembered in `acc`, starting with `initialValue`, becoming the final return value in the process.
131+
Calls the specified reducer function with each value of the array, resulting in a single return value. The respective previous reducer function's return value is remembered in `accumValue`, starting with `initialValue`, becoming the final return value in the process.
132132

133133
* ```ts
134134
function reduceRight<U>(
135-
fn: (acc: U, cur: T, idx: i32, src: Array) => U,
135+
fn: (accumValue: U, currentValue: T, index: i32, self: Array<T>) => U,
136136
initialValue: U
137137
): U
138138
```
@@ -154,7 +154,7 @@ arr[0]; // now it works 😊
154154
Returns a shallow copy of the array's values from `begin` inclusive to `end` exclusive, as a new array. If omitted, `end` defaults to the end of the array.
155155

156156
* ```ts
157-
function some(fn: (value: T, index: i32, array: Array<T>) => bool): bool
157+
function some(fn: (value: T, index: i32, self: Array<T>) => bool): bool
158158
```
159159
Calls the specified function with every value of the array until it finds the first value for which the function returns `true`, returning `true`. Returns `false` otherwise or if the array is empty.
160160

src/stdlib/staticarray.md

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The StaticArray API is similar to the [Array API](./array.md), with the importan
1818
## Static members
1919

2020
* ```ts
21-
function fromArray<T>(source: T[]): StaticArray<T>
21+
function fromArray<T>(source: Array<T>): StaticArray<T>
2222
```
2323
Creates a static array from a normal array.
2424

@@ -49,10 +49,45 @@ The StaticArray API is similar to the [Array API](./array.md), with the importan
4949
Gets the element at the specified position. This method allows for positive and negative integers. Negative integers count back from the last element.
5050

5151
* ```ts
52-
function concat(other: T[]): T[]
52+
function concat(other: Array<T>): Array<T>
5353
```
5454
Concatenates the values of this static and the other normal array to a new normal array, in this order.
5555

56+
* ```ts
57+
function copyWithin(target: i32, start: i32, end?: i32): this
58+
```
59+
Copies a region of an array's values over the respective values starting at the target location.
60+
61+
* ```ts
62+
function every(fn: (value: T, index: i32, self: StaticArray<T>) => bool): bool
63+
```
64+
Calls the specified function with every value of the array until it finds the first value for which the function returns `false`. Returns `true` if all functions returned `true` or the array is empty, otherwise `false`.
65+
66+
* ```ts
67+
function fill(value: T, start?: i32, end?: i32): this
68+
```
69+
Replaces the values of the array from `start` inclusive to `end` exclusive in place with the specified value, returning the array.
70+
71+
* ```ts
72+
function filter(fn: (value: T, index: i32, self: StaticArray<T>) => bool): Array<T>
73+
```
74+
Calls the specified function with every value of the array, returning a new array with all values for which the function returned `true`.
75+
76+
* ```ts
77+
function findIndex(fn: (value: T, index: i32, self: StaticArray<T>) => bool): i32
78+
```
79+
Calls the specified function with every value of the array until it finds the first value for which the function returns `true`, returning its index. Returns `-1` if that's never the case.
80+
81+
* ```ts
82+
function findLastIndex(fn: (value: T, index: i32, self: StaticArray<T>) => bool): i32;
83+
```
84+
Calls the specified function with every value of the array starting at the end until it finds the first value for which the function returns `true`, returning its index. Returns `-1` if that's never the case.
85+
86+
* ```ts
87+
function forEach(fn: (value: T, index: i32, self: StaticArray<T>) => void): void
88+
```
89+
Calls the specified function with every value of the array.
90+
5691
* ```ts
5792
function includes(value: T, fromIndex?: i32): bool
5893
```
@@ -74,15 +109,46 @@ The StaticArray API is similar to the [Array API](./array.md), with the importan
74109
Gets the last index where the specified value can be found in the array. Returns `-1` if not found.
75110

76111
* ```ts
77-
function slice(start?: i32, end?: i32): T[]
112+
function map<U>(fn: (value: T, index: i32, self: StaticArray<T>) => U): Array<U>
113+
```
114+
Calls the specified function with every value of the array, returning a new array of the function's return values.
115+
116+
* ```ts
117+
function slice(start?: i32, end?: i32): Array<T>
78118
```
79119
Returns a shallow copy of this static array's values from `begin` inclusive to `end` exclusive, as a new normal array. If omitted, `end` defaults to the end of the array.
80120

121+
* ```ts
122+
function some(fn: (value: T, index: i32, self: StaticArray<T>) => bool): bool
123+
```
124+
Calls the specified function with every value of the array until it finds the first value for which the function returns `true`, returning `true`. Returns `false` otherwise or if the array is empty.
125+
81126
* ```ts
82127
function sort(fn?: (a: T, b: T) => i32): this
83128
```
84129
Sorts the values of the array in place, using the specified comparator function, modifying the array before returning it. The comparator returning a negative value means `a < b`, a positive value means `a > b` and `0` means that both are equal. Unlike in JavaScript, where an implicit conversion to strings is performed, the comparator defaults to compare two values of type `T`.
85130

131+
* ```ts
132+
function reduce<U>(
133+
fn: (accumValue: U, currentValue: T, index: i32, self: StaticArray<T>) => U,
134+
initialValue: U
135+
): U
136+
```
137+
Calls the specified reducer function with each value of the array, resulting in a single return value. The respective previous reducer function's return value is remembered in `accumValue`, starting with `initialValue`, becoming the final return value in the process.
138+
139+
* ```ts
140+
function reduceRight<U>(
141+
fn: (accumValue: U, currentValue: T, index: i32, self: StaticArray<T>) => U,
142+
initialValue: U
143+
): U
144+
```
145+
Calls the specified reducer function with each value of the array, from right to left, resulting in a single return value. See `Array#reduce` for the reducer function's signature.
146+
147+
* ```ts
148+
function reverse(): this
149+
```
150+
Reverses an array's values in place, modifying the array before returning it.
151+
86152
* ```ts
87153
function toString(): string
88154
```

src/stdlib/typedarray.md

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The TypedArray API works very much like JavaScript's \([MDN](https://developer.m
2727
## Constructor
2828

2929
* ```ts
30-
new TypedArray<T>(length: i32)
30+
new TypedArray(length: i32)
3131
```
3232
Constructs a new typed array view with a new backing buffer and all values initialized to zero. See `wrap` below for wrapping a raw buffer.
3333

@@ -39,7 +39,7 @@ The TypedArray API works very much like JavaScript's \([MDN](https://developer.m
3939
Number of bytes per element.
4040
4141
* ```ts
42-
function wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): TypedArray<T>
42+
function wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): TypedArray
4343
```
4444
Wraps a raw buffer to be viewed as a sequence of values of the typed array's value type. This is equivalent to the respective alternative constructor signature in JS but exists because there is no function overloading \(yet\).
4545

@@ -70,9 +70,7 @@ The TypedArray API works very much like JavaScript's \([MDN](https://developer.m
7070
### Methods
7171

7272
* ```ts
73-
function every(
74-
fn: (value: T, index: i32, self: TypedArray) => bool
75-
): bool
73+
function every(fn: (value: T, index: i32, self: TypedArray) => bool): bool
7674
```
7775
Calls the specified function with every value of the array until it finds the first value for which the function returns `false`. Returns `true` if all functions returned `true` or the array is empty, otherwise `false`.
7876

@@ -82,23 +80,17 @@ The TypedArray API works very much like JavaScript's \([MDN](https://developer.m
8280
Replaces the values of the array from `start` inclusive to `end` exclusive in place with the specified value, returning the array.
8381

8482
* ```ts
85-
function findIndex(
86-
fn: (value: T, index: i32, self: TypedArray) => bool
87-
): i32
83+
function findIndex(fn: (value: T, index: i32, self: TypedArray) => bool): i32
8884
```
8985
Calls the specified function with every value of the array until it finds the first value for which the function returns `true`, returning its index. Returns `-1` if that's never the case.
9086

9187
* ```ts
92-
function findLastIndex(
93-
fn: (value: T, index: i32, self: TypedArray) => bool
94-
): i32;
88+
function findLastIndex(fn: (value: T, index: i32, self: TypedArray) => bool): i32
9589
```
9690
Calls the specified function with every value of the array starting at the end until it finds the first value for which the function returns `true`, returning its index. Returns `-1` if that's never the case.
9791

9892
* ```ts
99-
function forEach(
100-
fn: (value: T, index: i32, self: TypedArray) => void
101-
): void
93+
function forEach(fn: (value: T, index: i32, self: TypedArray) => void): void
10294
```
10395
Calls the specified function with every value of the array.
10496

@@ -118,23 +110,21 @@ The TypedArray API works very much like JavaScript's \([MDN](https://developer.m
118110
Gets the last index where the specified value can be found in the array. Returns `-1` if not found.
119111

120112
* ```ts
121-
function map(
122-
fn: (value: T, index: i32, self: TypedArray) => T
123-
): TypedArray
113+
function map(fn: (value: T, index: i32, self: TypedArray) => T): TypedArray
124114
```
125115
Calls the specified function with every value of the array, returning a new array of the function's return values.
126116

127117
* ```ts
128118
function reduce<U>(
129-
fn: (acc: U, cur: T, idx: i32, src: Array) => U,
119+
fn: (accumValue: U, currentValue T, index: i32, self: TypedArray) => U,
130120
initialValue: U
131121
): U
132122
```
133-
Calls the specified reducer function with each value of the array, resulting in a single return value. The respective previous reducer function's return value is remembered in `acc`, starting with `initialValue`, becoming the final return value in the process.
123+
Calls the specified reducer function with each value of the array, resulting in a single return value. The respective previous reducer function's return value is remembered in `accumValue`, starting with `initialValue`, becoming the final return value in the process.
134124

135125
* ```ts
136126
function reduceRight<U>(
137-
fn: (acc: U, cur: T, idx: i32, src: Array) => U,
127+
fn: (accumValue: U, currentValue: T, index: i32, self: TypedArray) => U,
138128
initialValue: U
139129
): U
140130
```
@@ -151,9 +141,7 @@ The TypedArray API works very much like JavaScript's \([MDN](https://developer.m
151141
Sets the typed array values (starting at `offset`, or 0), reading input values from a specified `source` typed array.
152142

153143
* ```ts
154-
function some(
155-
fn: (value: T, index: i32, self: TypedArray) => bool
156-
): bool
144+
function some(fn: (value: T, index: i32, self: TypedArray) => bool): bool
157145
```
158146
Calls the specified function with every value of the array until it finds the first value for which the function returns `true`, returning `true`. Returns `false` otherwise or if the array is empty.
159147

0 commit comments

Comments
 (0)