@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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@zelgadis87/utils-core",
4
- "version": "5.2.5",
4
+ "version": "5.2.7",
5
5
  "author": "Zelgadis87",
6
6
  "license": "ISC",
7
7
  "private": false,
@@ -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
+ }