@zelgadis87/utils-core 5.2.6 → 5.2.8

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.6",
4
+ "version": "5.2.8",
5
5
  "author": "Zelgadis87",
6
6
  "license": "ISC",
7
7
  "private": false,
package/src/Optional.ts CHANGED
@@ -54,11 +54,11 @@ export class Optional<T> implements TOptional<T> {
54
54
 
55
55
  public ifEmpty( callback: TVoidFunction ) {
56
56
  if ( this.isEmpty() )
57
- callback();
57
+ return callback();
58
58
  }
59
59
  public ifPresent( callback: TConsumer<T> ) {
60
60
  if ( this.isPresent() )
61
- callback( this.get() );
61
+ return callback( this.get() );
62
62
  }
63
63
  public ifPresentThenClear( callback: TConsumer<T> ) {
64
64
  if ( this.isPresent() ) {
@@ -66,11 +66,12 @@ export class Optional<T> implements TOptional<T> {
66
66
  this.clear();
67
67
  }
68
68
  }
69
+
69
70
  public apply( callbackIfPresent: TConsumer<T>, callbackIfEmpty: TVoidFunction ) {
70
71
  if ( this.isEmpty() ) {
71
- callbackIfEmpty();
72
+ return callbackIfEmpty();
72
73
  } else {
73
- callbackIfPresent( this.get() );
74
+ return callbackIfPresent( this.get() );
74
75
  }
75
76
  }
76
77
 
@@ -218,9 +219,10 @@ export type TOptional<T> = {
218
219
  isEmpty(): boolean;
219
220
  isPresent(): boolean;
220
221
 
221
- ifEmpty: ( callback: TVoidFunction ) => void;
222
- ifPresent: ( callback: TConsumer<T> ) => void;
223
- apply( callbackIfPresent: TConsumer<T>, callbackIfEmpty: TVoidFunction ): void;
222
+ ifEmpty( callback: TVoidFunction ): void;
223
+ ifPresent( callback: TConsumer<T> ): void;
224
+ apply<RP = void, RE = void>( callbackIfPresent: TFunction<T, RP>, callbackIfEmpty: TProducer<RE> ): void;
225
+
224
226
  throwIfPresent: ( errorGenerator: TFunction<T, Error> ) => TEmptyOptional<T>;
225
227
 
226
228
  /** @deprecated[2025.07.25]: Replace with {@link orElseReturn} (drop-in replacement) */
@@ -188,6 +188,6 @@ export function unzip<T, R>( arr: [ T, R ][] ): [ T[], R[] ] {
188
188
  */
189
189
  export function arrayGet<T>( arr: TReadableArray<T>, index: number ) {
190
190
  if ( index < 0 || index >= arr.length )
191
- return Optional.empty();
192
- return Optional.of( arr[ index ] );
191
+ return Optional.empty<T>();
192
+ return Optional.of<T>( arr[ index ] );
193
193
  }