@zelgadis87/utils-core 5.4.1 → 5.4.3
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/.rollup/index.cjs +2 -2
- package/.rollup/index.cjs.map +1 -1
- package/.rollup/index.d.ts +17 -1
- package/.rollup/index.mjs +2 -2
- package/.rollup/index.mjs.map +1 -1
- package/.rollup/tsconfig.tsbuildinfo +1 -1
- package/CHANGELOG.md +12 -0
- package/package.json +1 -1
- package/src/Optional.ts +28 -4
- package/src/utils/arrays.ts +1 -1
package/.rollup/index.d.ts
CHANGED
|
@@ -193,6 +193,14 @@ type TEmptyOptional<T> = TOptional<T> & {
|
|
|
193
193
|
mapTo<R>(mapper: TFunction<T, R>): TEmptyOptional<T>;
|
|
194
194
|
flatMapTo<R>(mapper: TFunction<T, TOptional<R>>): TEmptyOptional<T>;
|
|
195
195
|
filter(predicate: TPredicate<T>): TEmptyOptional<T>;
|
|
196
|
+
orElseReturn: <R>(newValue: R) => R;
|
|
197
|
+
orElseProduce: <R>(newValueProducer: TProducer<R>) => R;
|
|
198
|
+
orElseReturnNullable: <R>(newValue: R | null | undefined) => TOptional<R>;
|
|
199
|
+
orElseProduceNullable: <R>(newValueProducer: TProducer<R | null | undefined>) => TOptional<R>;
|
|
200
|
+
orElseReturnAndApply: <R>(newValue: R) => R;
|
|
201
|
+
orElseProduceAndApply: <R>(newValueProducer: TProducer<R>) => R;
|
|
202
|
+
orElseReturnNullableAndApply: <R>(newValue: R | null | undefined) => TOptional<R>;
|
|
203
|
+
orElseProduceNullableAndApply: <R>(newValueProducer: TProducer<R | null | undefined>) => TOptional<R>;
|
|
196
204
|
};
|
|
197
205
|
type TPresentOptional<T> = TOptional<T> & {
|
|
198
206
|
get(): T;
|
|
@@ -201,6 +209,14 @@ type TPresentOptional<T> = TOptional<T> & {
|
|
|
201
209
|
apply<RP = void, RE = void>(callbackIfPresent: TFunction<T, RP>, callbackIfEmpty: TProducer<RE>): RP;
|
|
202
210
|
mapTo<R>(mapper: TFunction<T, R>): TPresentOptional<R>;
|
|
203
211
|
flatMapTo<R>(mapper: TFunction<T, TOptional<R>>): TOptional<R>;
|
|
212
|
+
orElseReturn: (newValue: T) => T;
|
|
213
|
+
orElseProduce: (newValueProducer: TProducer<T>) => T;
|
|
214
|
+
orElseReturnNullable: (newValue: T | null | undefined) => TOptional<T>;
|
|
215
|
+
orElseProduceNullable: (newValueProducer: TProducer<T | null | undefined>) => TOptional<T>;
|
|
216
|
+
orElseReturnAndApply: (newValue: T) => T;
|
|
217
|
+
orElseProduceAndApply: (newValueProducer: TProducer<T>) => T;
|
|
218
|
+
orElseReturnNullableAndApply: (newValue: T | null | undefined) => TOptional<T>;
|
|
219
|
+
orElseProduceNullableAndApply: (newValueProducer: TProducer<T | null | undefined>) => TOptional<T>;
|
|
204
220
|
};
|
|
205
221
|
declare class ErrorGetEmptyOptional extends Error {
|
|
206
222
|
constructor();
|
|
@@ -921,7 +937,7 @@ declare function unzip<T, R>(arr: [T, R][]): [T[], R[]];
|
|
|
921
937
|
* @param index - The index of the element to retrieve
|
|
922
938
|
* @returns An Optional containing the element at the index, or empty if index is out of bounds
|
|
923
939
|
*/
|
|
924
|
-
declare function arrayGet<T>(arr: TReadableArray<T>, index: number):
|
|
940
|
+
declare function arrayGet<T>(arr: TReadableArray<T>, index: number): TOptional<T>;
|
|
925
941
|
|
|
926
942
|
declare function isTrue(x: unknown): x is true;
|
|
927
943
|
declare function isFalse(x: unknown): x is false;
|
package/.rollup/index.mjs
CHANGED
|
@@ -337,10 +337,10 @@ class Optional {
|
|
|
337
337
|
throw errorProducer(this.get());
|
|
338
338
|
}
|
|
339
339
|
mapTo(mapper) {
|
|
340
|
-
return this.
|
|
340
|
+
return this.apply(() => Optional.ofNullable(mapper(this.get())), () => Optional.empty());
|
|
341
341
|
}
|
|
342
342
|
flatMapTo(mapper) {
|
|
343
|
-
return this.
|
|
343
|
+
return this.apply(() => mapper(this.get()), () => Optional.empty());
|
|
344
344
|
}
|
|
345
345
|
filter(predicate) {
|
|
346
346
|
if (this.isEmpty())
|