@zelgadis87/utils-core 4.11.2 → 4.12.1
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/dist/Optional.d.ts +8 -4
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/esbuild/index.cjs +16 -2
- package/esbuild/index.cjs.map +2 -2
- package/esbuild/index.mjs +16 -2
- package/esbuild/index.mjs.map +2 -2
- package/package.json +1 -1
- package/src/Optional.ts +24 -7
package/package.json
CHANGED
package/src/Optional.ts
CHANGED
|
@@ -61,18 +61,33 @@ export class Optional<T> implements TOptional<T> {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
public orElse( newValue: T
|
|
65
|
-
if ( this.
|
|
66
|
-
return
|
|
64
|
+
public orElse( newValue: T ) {
|
|
65
|
+
if ( this.isPresent() ) {
|
|
66
|
+
return this._value;
|
|
67
|
+
} else {
|
|
68
|
+
return newValue;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
public orElseGet( newValueProducer: TProducer<T> ) {
|
|
72
|
+
if ( this.isPresent() ) {
|
|
73
|
+
return this._value;
|
|
74
|
+
} else {
|
|
75
|
+
return newValueProducer();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public orElseNullable( newValue: T | null | undefined ) {
|
|
80
|
+
if ( this.isEmpty() ) return Optional.ofNullable( newValue );
|
|
67
81
|
return this as TPresentOptional<T>;
|
|
68
82
|
}
|
|
69
|
-
public
|
|
83
|
+
public orElseGetNullable( newValueProducer: TProducer<T | null | undefined> ) {
|
|
70
84
|
if ( this.isEmpty() ) {
|
|
71
|
-
const newValue =
|
|
85
|
+
const newValue = newValueProducer();
|
|
72
86
|
return Optional.ofNullable( newValue );
|
|
73
87
|
}
|
|
74
88
|
return this as TPresentOptional<T>;
|
|
75
89
|
}
|
|
90
|
+
|
|
76
91
|
public orElseThrow( errorProducer: TProducer<Error> ) {
|
|
77
92
|
if ( this.isEmpty() )
|
|
78
93
|
throw errorProducer();
|
|
@@ -138,8 +153,10 @@ export type TOptional<T> = {
|
|
|
138
153
|
ifPresent: ( callback: TConsumer<T> ) => void;
|
|
139
154
|
apply( callbackIfPresent: TConsumer<T>, callbackIfEmpty: TVoidFunction ): void;
|
|
140
155
|
|
|
141
|
-
orElse: ( newValue: T
|
|
142
|
-
orElseGet: (
|
|
156
|
+
orElse: ( newValue: T ) => T;
|
|
157
|
+
orElseGet: ( newValueProducer: TProducer<T> ) => T;
|
|
158
|
+
orElseNullable: ( newValue: T | null | undefined ) => TOptional<T>;
|
|
159
|
+
orElseGetNullable: ( newValueProducer: TProducer<T | null | undefined> ) => TOptional<T>;
|
|
143
160
|
orElseThrow: ( errorProducer: TProducer<Error> ) => TPresentOptional<T>;
|
|
144
161
|
|
|
145
162
|
mapTo<R>( mapper: TFunction<T, R> ): TOptional<R>;
|