@zelgadis87/utils-core 5.2.5 → 5.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/arrays.d.ts +8 -0
- package/esbuild/index.cjs +7 -0
- package/esbuild/index.cjs.map +2 -2
- package/esbuild/index.mjs +6 -0
- package/esbuild/index.mjs.map +2 -2
- package/package.json +1 -1
- package/src/utils/arrays.ts +13 -0
package/package.json
CHANGED
package/src/utils/arrays.ts
CHANGED
|
@@ -178,3 +178,16 @@ export function unzip<T, R>( arr: [ T, R ][] ): [ T[], R[] ] {
|
|
|
178
178
|
return [ [ ...ts, t ], [ ...rs, r ] ];
|
|
179
179
|
}, [ [], [] ] as [ T[], R[] ] );
|
|
180
180
|
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Gets the element at the specified index in the array, wrapped in an Optional.
|
|
184
|
+
* Returns an empty Optional if the index is out of bounds (negative or >= array length).
|
|
185
|
+
* @param arr - The array to get the element from
|
|
186
|
+
* @param index - The index of the element to retrieve
|
|
187
|
+
* @returns An Optional containing the element at the index, or empty if index is out of bounds
|
|
188
|
+
*/
|
|
189
|
+
export function arrayGet<T>( arr: TReadableArray<T>, index: number ) {
|
|
190
|
+
if ( index < 0 || index >= arr.length )
|
|
191
|
+
return Optional.empty<T>();
|
|
192
|
+
return Optional.of<T>( arr[ index ] );
|
|
193
|
+
}
|