@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/CHANGELOG.md +8 -1
- package/dist/Optional.d.ts +3 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/arrays.d.ts +1 -1
- package/esbuild/index.cjs +4 -4
- package/esbuild/index.cjs.map +2 -2
- package/esbuild/index.mjs +4 -4
- package/esbuild/index.mjs.map +2 -2
- package/package.json +1 -1
- package/src/Optional.ts +9 -7
- package/src/utils/arrays.ts +2 -2
package/package.json
CHANGED
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
|
|
222
|
-
ifPresent
|
|
223
|
-
apply( callbackIfPresent:
|
|
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) */
|
package/src/utils/arrays.ts
CHANGED
|
@@ -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
|
}
|