@zelgadis87/utils-core 5.2.7 → 5.2.9

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.7",
4
+ "version": "5.2.9",
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> ): RP | RE;
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) */
@@ -253,11 +255,13 @@ export type TEmptyOptional<T> = TOptional<T> & {
253
255
  get(): never;
254
256
  isEmpty(): true;
255
257
  isPresent(): false;
258
+ apply<RP = void, RE = void>( callbackIfPresent: TFunction<T, RP>, callbackIfEmpty: TProducer<RE> ): RE;
256
259
  }
257
260
  export type TPresentOptional<T> = TOptional<T> & {
258
261
  get(): T;
259
262
  isEmpty(): false;
260
263
  isPresent(): true;
264
+ apply<RP = void, RE = void>( callbackIfPresent: TFunction<T, RP>, callbackIfEmpty: TProducer<RE> ): RP;
261
265
  }
262
266
 
263
267
  export class ErrorGetEmptyOptional extends Error {