You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `initialValues` parameter also accepts a callback, which you can use to dynamically create items for each position in the matrix.
75
+
The `initialValues` parameter can also be a callback, which you can use to dynamically create items for each position in the matrix. The callback can accept an argument which will resolve to the current vector co-ordinates at each point in the matrix. This can allow you to populate your matrix in a "self-aware" way.
76
76
77
77
```js
78
-
// create a 10x10x10 array, with each point a different random number between one and 10
78
+
// create a 10x10x10 array, with each point a different random number between one and 9
@@ -85,7 +98,7 @@ This package comes with type definitions to provide type-safety when working wit
85
98
86
99
Up to and including four dimensions, returned arrays will be given a specific type dictated by `T` and the number of dimensions, where `T` is the type of the value passed to the functions `initialValues` parameter (or `unknown` if not set).
87
100
88
-
For example, a three-dimensional array of numbers will be of type `number[][][]`. Points within the matrix can then only be reassigned to numbers. TypeScript's compiler will present errors when any reassignments are of the wrong type, including if they are at an incorrect depth in the array.
101
+
For example, a three-dimensional array of numbers will be of type `number[][][]`. Points within the matrix can then only be reassigned to numbers. TypeScript's compiler will present errors when any reassignments are of the wrong type, including if they are at an incorrect depth in the array. This type-safety also exists when callbacks are used to dynamically populate your matrix.
89
102
90
103
```ts
91
104
const threeDNumberArray =makeMatrix([2, 6, 5], 0); // return type of number[][][]
@@ -104,7 +117,7 @@ Above four dimensions, the returned array will have the generic type `Matrix<T>`
104
117
For more type-safety at these levels of dimensionality, it is recomended that you add more specific type annotations to your variables:
0 commit comments