@zelgadis87/utils-core 5.5.0-beta.4 → 6.0.0-beta.6

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.
@@ -97,98 +97,81 @@ declare function pipedInvoke<T, A, B, C, D, E, F, G, H, I>(op1: TFunction<T, A>,
97
97
  declare function pipedInvoke<T, A, B, C, D, E, F, G, H, I>(op1: TFunction<T, A>, op2: TFunction<A, B>, op3: TFunction<B, C>, op4: TFunction<C, D>, op5: TFunction<D, E>, op6: TFunction<E, F>, op7: TFunction<F, G>, op8: TFunction<G, H>, op9: TFunction<H, I>, ...operations: TFunction<any, any>[]): TFunction<T, unknown>;
98
98
  declare function pipedInvokeFromArray<T, R>(fns: Array<TFunction<any, any>>): TFunction<any, any>;
99
99
 
100
- declare class Optional<T> implements TOptional<T> {
100
+ declare class OptionalClz<T> implements TOptional<T> {
101
101
  private _present;
102
102
  private _value;
103
103
  private constructor();
104
- getRawValue(): T | undefined;
105
- /** @deprecated[2026.04.07]: Replace with {@link getOrElseThrow} (drop-in replacement with no arguments) */
106
104
  get(): T;
107
105
  getOrElseThrow(): T;
108
106
  getOrElseThrow(errorProducer: TProducer<Error>): T;
109
- set(t: T): void;
110
- protected setNullable(t: T | null | undefined): void | this;
111
- clear(): void;
112
107
  isEmpty(): this is TEmptyOptional<T>;
113
108
  isPresent(): this is TPresentOptional<T>;
114
109
  ifEmpty(callback: TVoidFunction): void;
115
110
  ifPresent(callback: TConsumer<T>): void;
116
- ifPresentThenClear(callback: TConsumer<T>): void;
117
- apply(callbackIfPresent: TConsumer<T>, callbackIfEmpty: TVoidFunction): any;
111
+ /**
112
+ * Dispatches to one of two callbacks based on whether a value is present.
113
+ * Equivalent to `fold` (fp-ts), `match` (effect/Scala), and `ifPresentOrElse` (Java, but with return values).
114
+ * @param callbackIfPresent - called with the current value when present; its return value is forwarded
115
+ * @param callbackIfEmpty - called when empty; its return value is forwarded
116
+ * @returns the return value of whichever callback was invoked
117
+ */
118
+ apply<RP = void, RE = void>(callbackIfPresent: TFunction<T, RP>, callbackIfEmpty: TProducer<RE>): RP | RE;
118
119
  orElseReturn(newValue: T): T;
119
- orElse: (newValue: T) => T;
120
120
  orElseReturnNull(): T | null;
121
121
  orElseReturnUndefined(): T | undefined;
122
122
  orElseProduce(newValueProducer: TProducer<T>): T;
123
- orElseGet: (newValueProducer: TProducer<T>) => T;
124
- orElseReturnAndApply(newValue: T): T;
125
- orElseProduceAndApply(newValueProducer: TProducer<T>): T;
126
- orElseReturnNullableAndApply(newValue: T | null | undefined): TOptional<T>;
127
- orElseProduceNullableAndApply(newValueProducer: TProducer<T | null | undefined>): TOptional<T>;
128
- orElseReturnNullable(newValue: T | null | undefined): any;
129
- orElseNullable: (newValue: T | null | undefined) => any;
130
- orElseProduceNullable(newValueProducer: TProducer<T | null | undefined>): any;
131
- orElseGetNullable: (newValueProducer: TProducer<T | null | undefined>) => any;
123
+ orElseReturnNullable(newValue: T | null | undefined): TOptional<T>;
124
+ orElseProduceNullable(newValueProducer: TProducer<T | null | undefined>): TOptional<T>;
132
125
  orElseThrow(errorProducer: TProducer<Error>): TPresentOptional<T>;
133
- throwIfPresent(errorProducer: TFunction<T, Error>): any;
134
- mapTo<R>(mapper: TFunction<T, R | null | undefined>): any;
135
- flatMapTo<R>(mapper: TFunction<T, TOptional<R>>): any;
126
+ throwIfPresent(errorProducer: TFunction<T, Error>): TEmptyOptional<T>;
127
+ mapTo<R>(mapper: TFunction<T, R>): TPresentOptional<R> | TEmptyOptional<R>;
128
+ flatMapTo<R>(mapper: TFunction<T, TOptional<R>>): TOptional<R> | TEmptyOptional<R>;
136
129
  filter(predicate: TPredicate<T>): this | TEmptyOptional<T>;
137
130
  static empty<T>(): TEmptyOptional<T>;
131
+ /**
132
+ * Creates a present optional wrapping a non-null value.
133
+ * Throws {@link ErrorCannotInstantiatePresentOptionalWithEmptyValue} if `t` is null or undefined.
134
+ *
135
+ * ⚠️ Do NOT use this method when the value may be null/undefined.
136
+ * Anti-pattern: `value ? Optional.of(value!) : Optional.empty()` → use {@link ofNullable} instead.
137
+ * Only use this when you are certain the value is defined (e.g. a literal, a validated input, or a narrowed type).
138
+ */
138
139
  static of<T>(t: T): TPresentOptional<T>;
140
+ /**
141
+ * Creates an optional that is present when `t` is defined, or empty when null/undefined.
142
+ * This is the idiomatic replacement for the anti-pattern:
143
+ * `value ? Optional.of(value!) : Optional.empty()` → `Optional.ofNullable(value)`
144
+ */
139
145
  static ofNullable<T>(t: T | null | undefined): TOptional<T>;
140
146
  static findInArray<T>(arr: ReadonlyArray<T>, predicate: TPredicate<T>): TOptional<T>;
141
147
  static findIndexInArray<T>(arr: ReadonlyArray<T>, predicate: TPredicate<T>): TOptional<number>;
142
148
  }
143
-
144
149
  type TOptional<T> = {
145
150
  /**
146
151
  * @deprecated[2026.04.07]: Replace with {@link getOrElseThrow} (drop-in replacement with no arguments)
147
152
  * @returns the currently stored value, if any; throws {@link ErrorGetEmptyOptional} otherwise;
148
153
  */
149
154
  get(): T;
150
- /**
151
- * @returns the currently stored value, if any; returns undefined otherwise;
152
- */
153
- getRawValue(): T | undefined;
154
155
  /**
155
156
  * @returns the currently stored value, if any; throws {@link ErrorGetEmptyOptional} if no errorProducer is provided, or the error generated by errorProducer otherwise;
156
157
  */
157
158
  getOrElseThrow(): T;
158
159
  getOrElseThrow(errorProducer: TProducer<Error>): T;
159
- /**
160
- * Places a new value inside this optional. Throws {@link ErrorSetEmptyOptional} if t is null or undefined.
161
- */
162
- set(t: T): void;
163
- /**
164
- * Clears the current value from this optional, if any.
165
- */
166
- clear(): void;
167
160
  isEmpty(): boolean;
168
161
  isPresent(): boolean;
169
162
  ifEmpty(callback: TVoidFunction): void;
170
163
  ifPresent(callback: TConsumer<T>): void;
171
164
  apply<RP = void, RE = void>(callbackIfPresent: TFunction<T, RP>, callbackIfEmpty: TProducer<RE>): RP | RE;
172
165
  throwIfPresent: (errorGenerator: TFunction<T, Error>) => TEmptyOptional<T>;
173
- /** @deprecated[2025.07.25]: Replace with {@link orElseReturn} (drop-in replacement) */
174
- orElse: (newValue: T) => T;
175
- /** @deprecated[2025.07.25]: Replace with {@link orElseProduce} (drop-in replacement) */
176
- orElseGet: (newValueProducer: TProducer<T>) => T;
177
- /** @deprecated[2025.07.25]: Replace with {@link orElseReturnNullabe} (drop-in replacement) */
178
- orElseNullable: (newValue: T | null | undefined) => TOptional<T>;
179
- /** @deprecated[2025.07.25]: Replace with {@link orElseProduceNullable} (drop-in replacement) */
180
- orElseGetNullable: (newValueProducer: TProducer<T | null | undefined>) => TOptional<T>;
181
166
  orElseReturn: (newValue: T) => T;
167
+ orElseReturnNull(): T | null;
168
+ orElseReturnUndefined(): T | undefined;
182
169
  orElseProduce: (newValueProducer: TProducer<T>) => T;
183
170
  orElseReturnNullable: (newValue: T | null | undefined) => TOptional<T>;
184
171
  orElseProduceNullable: (newValueProducer: TProducer<T | null | undefined>) => TOptional<T>;
185
- orElseReturnAndApply: (newValue: T) => T;
186
- orElseProduceAndApply: (newValueProducer: TProducer<T>) => T;
187
- orElseReturnNullableAndApply: (newValue: T | null | undefined) => TOptional<T>;
188
- orElseProduceNullableAndApply: (newValueProducer: TProducer<T | null | undefined>) => TOptional<T>;
189
172
  orElseThrow: (errorProducer: TProducer<Error>) => TPresentOptional<T>;
190
- mapTo<R>(mapper: TFunction<T, R>): TPresentOptional<R> | TEmptyOptional<T>;
191
- flatMapTo<R>(mapper: TFunction<T, TOptional<R>>): TOptional<R> | TEmptyOptional<T>;
173
+ mapTo<R>(mapper: TFunction<T, R>): TOptional<R>;
174
+ flatMapTo<R>(mapper: TFunction<T, TOptional<R>>): TOptional<R>;
192
175
  filter(predicate: TPredicate<T>): TOptional<T>;
193
176
  };
194
177
  type TEmptyOptional<T> = TOptional<T> & {
@@ -199,8 +182,8 @@ type TEmptyOptional<T> = TOptional<T> & {
199
182
  isEmpty(): true;
200
183
  isPresent(): false;
201
184
  apply<RP = void, RE = void>(callbackIfPresent: TFunction<T, RP>, callbackIfEmpty: TProducer<RE>): RE;
202
- mapTo<R>(mapper: TFunction<T, R>): TEmptyOptional<T>;
203
- flatMapTo<R>(mapper: TFunction<T, TOptional<R>>): TEmptyOptional<T>;
185
+ mapTo<R>(mapper: TFunction<T, R>): TEmptyOptional<R>;
186
+ flatMapTo<R>(mapper: TFunction<T, TOptional<R>>): TEmptyOptional<R>;
204
187
  filter(predicate: TPredicate<T>): TEmptyOptional<T>;
205
188
  orElseReturn: <R>(newValue: R) => R;
206
189
  orElseReturnNull(): null;
@@ -208,13 +191,8 @@ type TEmptyOptional<T> = TOptional<T> & {
208
191
  orElseProduce: <R>(newValueProducer: TProducer<R>) => R;
209
192
  orElseReturnNullable: <R>(newValue: R | null | undefined) => TOptional<R>;
210
193
  orElseProduceNullable: <R>(newValueProducer: TProducer<R | null | undefined>) => TOptional<R>;
211
- orElseReturnAndApply: <R>(newValue: R) => R;
212
- orElseProduceAndApply: <R>(newValueProducer: TProducer<R>) => R;
213
- orElseReturnNullableAndApply: <R>(newValue: R | null | undefined) => TOptional<R>;
214
- orElseProduceNullableAndApply: <R>(newValueProducer: TProducer<R | null | undefined>) => TOptional<R>;
215
194
  };
216
195
  type TPresentOptional<T> = TOptional<T> & {
217
- /** @deprecated[2026.04.07]: Replace with {@link getOrElseThrow} (drop-in replacement with no arguments) */
218
196
  get(): T;
219
197
  getOrElseThrow(): T;
220
198
  getOrElseThrow(errorProducer: TProducer<Error>): T;
@@ -229,17 +207,10 @@ type TPresentOptional<T> = TOptional<T> & {
229
207
  orElseProduce: (newValueProducer: TProducer<T>) => T;
230
208
  orElseReturnNullable: (newValue: T | null | undefined) => TOptional<T>;
231
209
  orElseProduceNullable: (newValueProducer: TProducer<T | null | undefined>) => TOptional<T>;
232
- orElseReturnAndApply: (newValue: T) => T;
233
- orElseProduceAndApply: (newValueProducer: TProducer<T>) => T;
234
- orElseReturnNullableAndApply: (newValue: T | null | undefined) => TOptional<T>;
235
- orElseProduceNullableAndApply: (newValueProducer: TProducer<T | null | undefined>) => TOptional<T>;
236
210
  };
237
211
  declare class ErrorGetEmptyOptional extends Error {
238
212
  constructor();
239
213
  }
240
- declare class ErrorSetEmptyOptional extends Error {
241
- constructor();
242
- }
243
214
  declare class ErrorCannotInstantiatePresentOptionalWithEmptyValue extends Error {
244
215
  constructor();
245
216
  }
@@ -560,7 +531,7 @@ declare class TimeInstant extends TimeBase<TimeInstant> {
560
531
  static builder(): TTimeInstantBuilder;
561
532
  static fromIso8601(str: string): TimeInstant;
562
533
  /**
563
- * @deprecated [2025.10.19]: Use fromIso8601 instead.
534
+ * @deprecated[2025.10.19]: Use fromIso8601 instead.
564
535
  */
565
536
  static tryFromIso8601: typeof TimeInstant.fromIso8601;
566
537
  static now(): TimeInstant;
@@ -704,16 +675,16 @@ type TSorterStepForNumbers<_T, Ret> = {
704
675
  }): Ret;
705
676
  };
706
677
  type TSorterStepForStrings<_T, Ret> = {
707
- /** @deprecated: Use inLexographicalOrder instead */ inLexographicalOrder(opts?: {
678
+ /** @deprecated[2025.09.29]: Use inLexicographicalOrder instead */ inLexographicalOrder(opts?: {
708
679
  nullsFirst?: boolean;
709
680
  }): Ret;
710
- /** @deprecated: Use inLexographicalOrderIgnoringCase instead */ inLexographicalOrderIgnoringCase(opts?: {
681
+ /** @deprecated[2025.09.29]: Use inLexicographicalOrderIgnoringCase instead */ inLexographicalOrderIgnoringCase(opts?: {
711
682
  nullsFirst?: boolean;
712
683
  }): Ret;
713
- /** @deprecated: Use inReverseLexographicalOrder instead */ inReverseLexographicalOrder(opts?: {
684
+ /** @deprecated[2025.09.29]: Use inReverseLexicographicalOrder instead */ inReverseLexographicalOrder(opts?: {
714
685
  nullsFirst?: boolean;
715
686
  }): Ret;
716
- /** @deprecated: Use inReverseLexographicalOrderIgnoringCase instead */ inReverseLexographicalOrderIgnoringCase(opts?: {
687
+ /** @deprecated[2025.09.29]: Use inReverseLexicographicalOrderIgnoringCase instead */ inReverseLexographicalOrderIgnoringCase(opts?: {
717
688
  nullsFirst?: boolean;
718
689
  }): Ret;
719
690
  inLexicographicalOrder(opts?: {
@@ -961,8 +932,6 @@ declare function isFalse(x: unknown): x is false;
961
932
  declare function dictToEntries<V, K extends string = string>(obj: Record<K, V>): [K, V][];
962
933
  declare function entriesToDict<V, K extends string = string>(entries: [K, V][]): Record<K, V>;
963
934
  declare function entriesToEntries<K1 extends string, V1, K2 extends string, V2>(dict: Record<K1, V1>, mapper: TFunction<[K1, V1], [K2, V2]>): Record<K2, V2>;
964
- /** @deprecated[2025.08.01]: Compatibility layer. */
965
- declare const mapEntries: typeof entriesToEntries;
966
935
  declare function entriesToList<K1 extends string, V1, R>(dict: Record<K1, V1>, mapper: TFunction<[K1, V1], R>): Array<R>;
967
936
 
968
937
  type TEmpty = Record<string, never>;
@@ -1071,7 +1040,7 @@ type TAsyncOperation<T, E = Error> = Promise<TOperation<T, E>>;
1071
1040
  type TOperationTuple<T, E = Error> = [T, undefined] | [undefined, E];
1072
1041
  type TAsyncOperationTuple<T, E = Error> = Promise<TOperationTuple<T, E>>;
1073
1042
  /**
1074
- * @deprecated Use `TOperation<T, OperationAggregateError<E>>` with `Operation.combine` instead.
1043
+ * @deprecated[2026.03.20]: Use `TOperation<T, OperationAggregateError<E>>` with `Operation.combine` instead.
1075
1044
  */
1076
1045
  type TValidation<T, E = Error> = {
1077
1046
  success: false;
@@ -1081,7 +1050,7 @@ type TValidation<T, E = Error> = {
1081
1050
  data: T;
1082
1051
  };
1083
1052
  /**
1084
- * @deprecated Use `TAsyncOperation<T, OperationAggregateError<E>>` with `Operation.combine` instead.
1053
+ * @deprecated[2026.03.20]: Use `TAsyncOperation<T, OperationAggregateError<E>>` with `Operation.combine` instead.
1085
1054
  */
1086
1055
  type TAsyncValidation<T, E = Error> = Promise<TValidation<T, E>>;
1087
1056
  /**
@@ -1277,7 +1246,7 @@ declare const NEVER: Promise<unknown>;
1277
1246
 
1278
1247
  /**
1279
1248
  * Returns a random integer in the range [min, max].
1280
- * @deprecated Use randomIntegerInInterval or randomDecimalInInterval instead
1249
+ * @deprecated[2026.03.17]: Use randomIntegerInInterval or randomDecimalInInterval instead.
1281
1250
  */
1282
1251
  declare function randomNumberInInterval(min: number, max: number): number;
1283
1252
  /**
@@ -1910,5 +1879,5 @@ declare class DataUpgrader<X extends TUpgradable, XLatest extends X> implements
1910
1879
  }
1911
1880
  declare function isUpgradable(obj: TJsonSerializable): obj is TUpgradable;
1912
1881
 
1913
- export { Cached, DataUpgrader, DataUpgraderBuilder, Deferred, DeferredCanceledError, ErrorCannotInstantiatePresentOptionalWithEmptyValue, ErrorGetEmptyOptional, ErrorSetEmptyOptional, Lazy, LazyAsync, LazyDictionary, Logger, NEVER, NonExhaustiveSwitchError, Operation, OperationAggregateError, Optional, PredicateBuilder, RandomTimeDuration, RateThrottler, Semaphore, Sorter, StringParts, TimeDuration, TimeFrequency, TimeInstant, TimeRange, TimeUnit, TimeoutError, alwaysFalse, alwaysTrue, and, arrayGet, arrayIncludes, asError, asPromise, average, averageBy, awaitAtMost, capitalizeWord, clamp, clampInt0_100, constant, constantFalse, constantNull, constantOne, constantTrue, constantUndefined, constantZero, cssDeclarationRulesDictionaryToCss, decrement, decrementBy, delayPromise, dictToEntries, dictToList, divideBy, ellipsis, ensureArray, ensureDefined, ensureNegativeNumber, ensureNonNegativeNumber, ensureNonPositiveNumber, ensurePositiveNumber, ensureReadableArray, entriesToDict, entriesToEntries, entriesToList, extendArray, extendArrayWith, fill, fillWith, filterMap, filterMapReduce, filterWithTypePredicate, findInArray, findIndexInArray, first, flatMapTruthys, getCauseMessageFromError, getCauseStackFromError, getMessageFromError, getStackFromError, groupByBoolean, groupByBooleanWith, groupByNumber, groupByNumberWith, groupByString, groupByStringWith, groupBySymbol, groupBySymbolWith, hashCode, havingMaxBy, havingMinBy, head, identity, ifDefined, ifNullOrUndefined, iff, includes, increment, incrementBy, indexByNumber, indexByNumberWith, indexByString, indexByStringWith, indexBySymbol, indexBySymbolWith, indexByWith, isAllowedTimeDuration, isArray, isDefined, isEmpty, isError, isFalse, isFunction, isNegativeNumber, isNullOrUndefined, isNullOrUndefinedOrEmpty, isNumber, isPositiveNumber, isString, isTimeInstant, isTrue, isUpgradable, isZero, jsonCloneDeep, last, listToDict, mapDefined, mapEntries, mapFirstTruthy, mapTruthys, max, maxBy, min, minBy, multiplyBy, noop, not, omitFromJsonObject, or, pad, padLeft, padRight, parseJson, parseTimeInstantBasicComponents, parseTimeInstantComponents, partition, pick, pipedInvoke, pipedInvokeFromArray, pluralize, promiseSequence, randomDecimalInInterval, randomId, randomIntegerInInterval, randomNumberInInterval, randomPick, randomPicks, range, repeat, reverse, round, roundAwayFromZero, roundToLower, roundToNearest, roundToUpper, roundTowardsZero, shallowArrayEquals, shallowRecordEquals, sortedArray, splitWords, stringToNumber, stringifyJson, sum, sumBy, tail, throttle, throwIfNullOrUndefined, transformCssDictionary, tryToParseJson, tryToParseNumber, uniq, uniqBy, uniqByKey, unzip, upsert, withTryCatch, withTryCatchAsync, wrapWithString, xor, zip };
1882
+ export { Cached, DataUpgrader, DataUpgraderBuilder, Deferred, DeferredCanceledError, ErrorCannotInstantiatePresentOptionalWithEmptyValue, ErrorGetEmptyOptional, Lazy, LazyAsync, LazyDictionary, Logger, NEVER, NonExhaustiveSwitchError, Operation, OperationAggregateError, OptionalClz as Optional, PredicateBuilder, RandomTimeDuration, RateThrottler, Semaphore, Sorter, StringParts, TimeDuration, TimeFrequency, TimeInstant, TimeRange, TimeUnit, TimeoutError, alwaysFalse, alwaysTrue, and, arrayGet, arrayIncludes, asError, asPromise, average, averageBy, awaitAtMost, capitalizeWord, clamp, clampInt0_100, constant, constantFalse, constantNull, constantOne, constantTrue, constantUndefined, constantZero, cssDeclarationRulesDictionaryToCss, decrement, decrementBy, delayPromise, dictToEntries, dictToList, divideBy, ellipsis, ensureArray, ensureDefined, ensureNegativeNumber, ensureNonNegativeNumber, ensureNonPositiveNumber, ensurePositiveNumber, ensureReadableArray, entriesToDict, entriesToEntries, entriesToList, extendArray, extendArrayWith, fill, fillWith, filterMap, filterMapReduce, filterWithTypePredicate, findInArray, findIndexInArray, first, flatMapTruthys, getCauseMessageFromError, getCauseStackFromError, getMessageFromError, getStackFromError, groupByBoolean, groupByBooleanWith, groupByNumber, groupByNumberWith, groupByString, groupByStringWith, groupBySymbol, groupBySymbolWith, hashCode, havingMaxBy, havingMinBy, head, identity, ifDefined, ifNullOrUndefined, iff, includes, increment, incrementBy, indexByNumber, indexByNumberWith, indexByString, indexByStringWith, indexBySymbol, indexBySymbolWith, indexByWith, isAllowedTimeDuration, isArray, isDefined, isEmpty, isError, isFalse, isFunction, isNegativeNumber, isNullOrUndefined, isNullOrUndefinedOrEmpty, isNumber, isPositiveNumber, isString, isTimeInstant, isTrue, isUpgradable, isZero, jsonCloneDeep, last, listToDict, mapDefined, mapFirstTruthy, mapTruthys, max, maxBy, min, minBy, multiplyBy, noop, not, omitFromJsonObject, or, pad, padLeft, padRight, parseJson, parseTimeInstantBasicComponents, parseTimeInstantComponents, partition, pick, pipedInvoke, pipedInvokeFromArray, pluralize, promiseSequence, randomDecimalInInterval, randomId, randomIntegerInInterval, randomNumberInInterval, randomPick, randomPicks, range, repeat, reverse, round, roundAwayFromZero, roundToLower, roundToNearest, roundToUpper, roundTowardsZero, shallowArrayEquals, shallowRecordEquals, sortedArray, splitWords, stringToNumber, stringifyJson, sum, sumBy, tail, throttle, throwIfNullOrUndefined, transformCssDictionary, tryToParseJson, tryToParseNumber, uniq, uniqBy, uniqByKey, unzip, upsert, withTryCatch, withTryCatchAsync, wrapWithString, xor, zip };
1914
1883
  export type { ICancelable, ICancelablePromise, IDataUpgrader, TAccumulator, TAllKeysOptional, TAnyFunction, TArrayable, TAsyncAnyFunction, TAsyncBiConsumer, TAsyncBiFunction, TAsyncBiPredicate, TAsyncConsumer, TAsyncFunction, TAsyncOperation, TAsyncOperationTuple, TAsyncPredicate, TAsyncProducer, TAsyncValidation, TAsyncVoidFunction, TBasicTimePattern, TBiConsumer, TBiFunction, TBiPredicate, TComparisonDirection, TComparisonFunction, TComparisonResult, TConditionalOptionalType, TConditionalParameter, TConditionalParameterOptions, TConsumer, TCssDeclarationRulesDictionary, TCssSelectorDeclarationRulesDictionary, TDayOfMonth, TDayOfWeek, TDigit, TDigit1_9, TEmpty, TEmptyArray, TEmptyObject, TEmptyOptional, TFourDigits, TFourDigitsMillisecond, TFourDigitsYear, TFunction, THasNever, THourOfDay, THtmlString, TIdentityFunction, TIntervalHandle, TIsEmptyObject, TIso8601DateString, TIso8601DateUtcString, TJsonArray, TJsonObject, TJsonPrimitive, TJsonSerializable, TKeysOfType, TLoggerOpts, TMaybe, TMillisecondOfSecond, TMinuteOfHour, TMonth, TMonthName, TNegativeNumber, TNumber0_10, TNumber0_100, TNumber0_1000, TNumber0_15, TNumber0_20, TNumber0_5, TNumber1_10, TNumericFloatingPointString, TNumericString, TOneDigit, TOperation, TOperationFailure, TOperationSuccess, TOperationTuple, TOptional, TOptionalKeysForType, TOptionsWithoutDefaults, TParseInt, TParseableInt, TPositiveNumber, TPredefinedTimeDuration, TPredicate, TPresentOptional, TPrettify, TPrimitive, TProducer, TPromisable, TReadableArray, TRelativeUrl, TReplaceType, TRequiredKeysForType, TSecondOfMinute, TSorter, TSorterBuilder, TStrictComparisonResult, TThreeDigits, TThreeDigitsMillisecond, TTimeInUnits, TTimeoutHandle, TTransformer, TTwoDigits, TTwoDigitsDate, TTwoDigitsHour, TTwoDigitsMinute, TTwoDigitsMonth, TTwoDigitsSecond, TTypePredicate, TUpToFourDigits, TUpToThreeDigits, TUpToTwoDigits, TUpgradable, TUrl, TValidTimeDuration, TValidation, TVoidFunction, TWeekNumber, TWithExtras, TWithRequiredProperties, TWithRequiredProperty, TYear, TZero };
package/.rollup/index.mjs CHANGED
@@ -211,7 +211,7 @@ function throwIfNullOrUndefined(source, errorProducer = () => new Error(`Unexpec
211
211
  return ifNullOrUndefined(source, () => { throw errorProducer(); });
212
212
  }
213
213
 
214
- class Optional {
214
+ class OptionalClz {
215
215
  _present;
216
216
  _value;
217
217
  constructor(t) {
@@ -219,10 +219,6 @@ class Optional {
219
219
  this._value = defined ? t : undefined;
220
220
  this._present = defined;
221
221
  }
222
- getRawValue() {
223
- return this._value;
224
- }
225
- /** @deprecated[2026.04.07]: Replace with {@link getOrElseThrow} (drop-in replacement with no arguments) */
226
222
  get() {
227
223
  return this.getOrElseThrow();
228
224
  }
@@ -231,22 +227,6 @@ class Optional {
231
227
  throw errorProducer();
232
228
  return this._value;
233
229
  }
234
- set(t) {
235
- if (isNullOrUndefined(t))
236
- throw new ErrorSetEmptyOptional();
237
- this._value = t;
238
- this._present = true;
239
- }
240
- setNullable(t) {
241
- if (isDefined(t)) {
242
- return this.set(t);
243
- }
244
- return this;
245
- }
246
- clear() {
247
- this._value = undefined;
248
- this._present = false;
249
- }
250
230
  isEmpty() {
251
231
  return !this._present;
252
232
  }
@@ -261,12 +241,13 @@ class Optional {
261
241
  if (this.isPresent())
262
242
  return callback(this.get());
263
243
  }
264
- ifPresentThenClear(callback) {
265
- if (this.isPresent()) {
266
- callback(this.get());
267
- this.clear();
268
- }
269
- }
244
+ /**
245
+ * Dispatches to one of two callbacks based on whether a value is present.
246
+ * Equivalent to `fold` (fp-ts), `match` (effect/Scala), and `ifPresentOrElse` (Java, but with return values).
247
+ * @param callbackIfPresent - called with the current value when present; its return value is forwarded
248
+ * @param callbackIfEmpty - called when empty; its return value is forwarded
249
+ * @returns the return value of whichever callback was invoked
250
+ */
270
251
  apply(callbackIfPresent, callbackIfEmpty) {
271
252
  if (this.isEmpty()) {
272
253
  return callbackIfEmpty();
@@ -283,7 +264,6 @@ class Optional {
283
264
  return newValue;
284
265
  }
285
266
  }
286
- orElse = this.orElseReturn.bind(this);
287
267
  orElseReturnNull() {
288
268
  return this.isPresent() ? this.get() : null;
289
269
  }
@@ -298,59 +278,18 @@ class Optional {
298
278
  return newValueProducer();
299
279
  }
300
280
  }
301
- orElseGet = this.orElseProduce.bind(this);
302
- orElseReturnAndApply(newValue) {
303
- if (this.isPresent()) {
304
- return this.get();
305
- }
306
- else {
307
- this.set(newValue);
308
- return newValue;
309
- }
310
- }
311
- orElseProduceAndApply(newValueProducer) {
312
- if (this.isPresent()) {
313
- return this.get();
314
- }
315
- else {
316
- const newValue = newValueProducer();
317
- this.set(newValue);
318
- return newValue;
319
- }
320
- }
321
- orElseReturnNullableAndApply(newValue) {
322
- if (this.isPresent()) {
323
- return this;
324
- }
325
- else {
326
- this.setNullable(newValue);
327
- return this;
328
- }
329
- }
330
- orElseProduceNullableAndApply(newValueProducer) {
331
- if (this.isPresent()) {
332
- return this;
333
- }
334
- else {
335
- const newValue = newValueProducer();
336
- this.setNullable(newValue);
337
- return this;
338
- }
339
- }
340
281
  orElseReturnNullable(newValue) {
341
282
  if (this.isEmpty())
342
- return Optional.ofNullable(newValue);
283
+ return OptionalClz.ofNullable(newValue);
343
284
  return this;
344
285
  }
345
- orElseNullable = this.orElseReturnNullable.bind(this);
346
286
  orElseProduceNullable(newValueProducer) {
347
287
  if (this.isEmpty()) {
348
288
  const newValue = newValueProducer();
349
- return Optional.ofNullable(newValue);
289
+ return OptionalClz.ofNullable(newValue);
350
290
  }
351
291
  return this;
352
292
  }
353
- orElseGetNullable = this.orElseProduceNullable.bind(this);
354
293
  orElseThrow(errorProducer) {
355
294
  if (this.isEmpty())
356
295
  throw errorProducer();
@@ -362,35 +301,48 @@ class Optional {
362
301
  throw errorProducer(this.get());
363
302
  }
364
303
  mapTo(mapper) {
365
- return this.apply(() => Optional.ofNullable(mapper(this.get())), () => Optional.empty());
304
+ return this.apply(() => OptionalClz.of(mapper(this.get())), () => OptionalClz.empty());
366
305
  }
367
306
  flatMapTo(mapper) {
368
- return this.apply(() => mapper(this.get()), () => Optional.empty());
307
+ return this.apply(() => mapper(this.get()), () => OptionalClz.empty());
369
308
  }
370
309
  filter(predicate) {
371
310
  if (this.isEmpty())
372
311
  return this;
373
312
  if (predicate(this.get()))
374
313
  return this;
375
- return Optional.empty();
314
+ return OptionalClz.empty();
376
315
  }
377
316
  static empty() {
378
- return new Optional(undefined);
317
+ return new OptionalClz(undefined);
379
318
  }
319
+ /**
320
+ * Creates a present optional wrapping a non-null value.
321
+ * Throws {@link ErrorCannotInstantiatePresentOptionalWithEmptyValue} if `t` is null or undefined.
322
+ *
323
+ * ⚠️ Do NOT use this method when the value may be null/undefined.
324
+ * Anti-pattern: `value ? Optional.of(value!) : Optional.empty()` → use {@link ofNullable} instead.
325
+ * Only use this when you are certain the value is defined (e.g. a literal, a validated input, or a narrowed type).
326
+ */
380
327
  static of(t) {
381
328
  if (isNullOrUndefined(t))
382
329
  throw new ErrorCannotInstantiatePresentOptionalWithEmptyValue();
383
- return new Optional(t);
330
+ return new OptionalClz(t);
384
331
  }
332
+ /**
333
+ * Creates an optional that is present when `t` is defined, or empty when null/undefined.
334
+ * This is the idiomatic replacement for the anti-pattern:
335
+ * `value ? Optional.of(value!) : Optional.empty()` → `Optional.ofNullable(value)`
336
+ */
385
337
  static ofNullable(t) {
386
- return new Optional(t);
338
+ return new OptionalClz(t);
387
339
  }
388
340
  static findInArray(arr, predicate) {
389
- return Optional.ofNullable(arr.find(predicate));
341
+ return OptionalClz.ofNullable(arr.find(predicate));
390
342
  }
391
343
  static findIndexInArray(arr, predicate) {
392
344
  const idx = arr.findIndex(predicate);
393
- return idx === -1 ? Optional.empty() : Optional.of(idx);
345
+ return idx === -1 ? OptionalClz.empty() : OptionalClz.of(idx);
394
346
  }
395
347
  }
396
348
  class ErrorGetEmptyOptional extends Error {
@@ -398,11 +350,6 @@ class ErrorGetEmptyOptional extends Error {
398
350
  super("Cannot retrieve a value from an empty Optional.");
399
351
  }
400
352
  }
401
- class ErrorSetEmptyOptional extends Error {
402
- constructor() {
403
- super("Cannot set a null or undefined value.");
404
- }
405
- }
406
353
  class ErrorCannotInstantiatePresentOptionalWithEmptyValue extends Error {
407
354
  constructor() {
408
355
  super("Cannot initialize a PresentOptional with a null or undefined value.");
@@ -839,11 +786,11 @@ function shallowArrayEquals(a, b) {
839
786
  }
840
787
  /** @deprecated[2026.03.01]: Use {@link Optional.findInArray} instead. */
841
788
  function findInArray(arr, predicate) {
842
- return Optional.findInArray(arr, predicate);
789
+ return OptionalClz.findInArray(arr, predicate);
843
790
  }
844
791
  /** @deprecated[2026.03.01]: Use {@link Optional.findIndexInArray} instead. */
845
792
  function findIndexInArray(arr, predicate) {
846
- return Optional.findIndexInArray(arr, predicate);
793
+ return OptionalClz.findIndexInArray(arr, predicate);
847
794
  }
848
795
  function zip(ts, rs) {
849
796
  if (ts.length !== rs.length)
@@ -864,8 +811,8 @@ function unzip(arr) {
864
811
  */
865
812
  function arrayGet(arr, index) {
866
813
  if (index < 0 || index >= arr.length)
867
- return Optional.empty();
868
- return Optional.of(arr[index]);
814
+ return OptionalClz.empty();
815
+ return OptionalClz.of(arr[index]);
869
816
  }
870
817
 
871
818
  function isTrue(x) {
@@ -1444,7 +1391,7 @@ const NEVER = new Promise(_resolve => { });
1444
1391
 
1445
1392
  /**
1446
1393
  * Returns a random integer in the range [min, max].
1447
- * @deprecated Use randomIntegerInInterval or randomDecimalInInterval instead
1394
+ * @deprecated[2026.03.17]: Use randomIntegerInInterval or randomDecimalInInterval instead.
1448
1395
  */
1449
1396
  function randomNumberInInterval(min, max) {
1450
1397
  return Math.floor(Math.random() * (max - min + 1) + min);
@@ -1499,8 +1446,6 @@ function entriesToDict(entries) {
1499
1446
  function entriesToEntries(dict, mapper) {
1500
1447
  return entriesToDict(dictToEntries(dict).map((entry) => mapper(entry)));
1501
1448
  }
1502
- /** @deprecated[2025.08.01]: Compatibility layer. */
1503
- const mapEntries = entriesToEntries;
1504
1449
  function entriesToList(dict, mapper) {
1505
1450
  return dictToEntries(dict).map((entry) => mapper(entry));
1506
1451
  }
@@ -2506,7 +2451,7 @@ class TimeInstant extends TimeBase {
2506
2451
  });
2507
2452
  }
2508
2453
  /**
2509
- * @deprecated [2025.10.19]: Use fromIso8601 instead.
2454
+ * @deprecated[2025.10.19]: Use fromIso8601 instead.
2510
2455
  */
2511
2456
  static tryFromIso8601 = this.fromIso8601;
2512
2457
  static now() {
@@ -4110,5 +4055,5 @@ class DataUpgraderBuilder {
4110
4055
  }
4111
4056
  }
4112
4057
 
4113
- export { Cached, DataUpgrader, DataUpgraderBuilder, Deferred, DeferredCanceledError, ErrorCannotInstantiatePresentOptionalWithEmptyValue, ErrorGetEmptyOptional, ErrorSetEmptyOptional, Lazy, LazyAsync, LazyDictionary, Logger, NEVER, NonExhaustiveSwitchError, Operation, OperationAggregateError, Optional, PredicateBuilder, RandomTimeDuration, RateThrottler, Semaphore, Sorter, StringParts, TimeDuration, TimeFrequency, TimeInstant, TimeRange, TimeUnit, TimeoutError, alwaysFalse, alwaysTrue, and, arrayGet, arrayIncludes, asError, asPromise, average, averageBy, awaitAtMost, capitalizeWord, clamp, clampInt0_100, constant, constantFalse, constantNull, constantOne, constantTrue, constantUndefined, constantZero, cssDeclarationRulesDictionaryToCss, decrement, decrementBy, delayPromise, dictToEntries, dictToList, divideBy, ellipsis, ensureArray, ensureDefined, ensureNegativeNumber, ensureNonNegativeNumber, ensureNonPositiveNumber, ensurePositiveNumber, ensureReadableArray, entriesToDict, entriesToEntries, entriesToList, extendArray, extendArrayWith, fill, fillWith, filterMap, filterMapReduce, filterWithTypePredicate, findInArray, findIndexInArray, first$1 as first, flatMapTruthys, getCauseMessageFromError, getCauseStackFromError, getMessageFromError, getStackFromError, groupByBoolean, groupByBooleanWith, groupByNumber, groupByNumberWith, groupByString, groupByStringWith, groupBySymbol, groupBySymbolWith, hashCode, havingMaxBy, havingMinBy, head, identity, ifDefined, ifNullOrUndefined, iff, includes, increment, incrementBy, indexByNumber, indexByNumberWith, indexByString, indexByStringWith, indexBySymbol, indexBySymbolWith, indexByWith, isAllowedTimeDuration, isArray, isDefined, isEmpty, isError, isFalse, isFunction, isNegativeNumber, isNullOrUndefined, isNullOrUndefinedOrEmpty, isNumber, isPositiveNumber, isString, isTimeInstant, isTrue, isUpgradable, isZero, jsonCloneDeep, last$1 as last, listToDict, mapDefined, mapEntries, mapFirstTruthy, mapTruthys, max, maxBy, min, minBy, multiplyBy, noop, not, omitFromJsonObject, or, pad, padLeft, padRight, parseJson, parseTimeInstantBasicComponents, parseTimeInstantComponents, partition, pick, pipedInvoke, pipedInvokeFromArray, pluralize, promiseSequence, randomDecimalInInterval, randomId, randomIntegerInInterval, randomNumberInInterval, randomPick, randomPicks, range, repeat, reverse$1 as reverse, round, roundAwayFromZero, roundToLower, roundToNearest, roundToUpper, roundTowardsZero, shallowArrayEquals, shallowRecordEquals, sortedArray, splitWords, stringToNumber, stringifyJson, sum, sumBy, tail, throttle, throwIfNullOrUndefined, transformCssDictionary, tryToParseJson, tryToParseNumber, uniq, uniqBy, uniqByKey, unzip, upsert, withTryCatch, withTryCatchAsync, wrapWithString, xor, zip };
4058
+ export { Cached, DataUpgrader, DataUpgraderBuilder, Deferred, DeferredCanceledError, ErrorCannotInstantiatePresentOptionalWithEmptyValue, ErrorGetEmptyOptional, Lazy, LazyAsync, LazyDictionary, Logger, NEVER, NonExhaustiveSwitchError, Operation, OperationAggregateError, OptionalClz as Optional, PredicateBuilder, RandomTimeDuration, RateThrottler, Semaphore, Sorter, StringParts, TimeDuration, TimeFrequency, TimeInstant, TimeRange, TimeUnit, TimeoutError, alwaysFalse, alwaysTrue, and, arrayGet, arrayIncludes, asError, asPromise, average, averageBy, awaitAtMost, capitalizeWord, clamp, clampInt0_100, constant, constantFalse, constantNull, constantOne, constantTrue, constantUndefined, constantZero, cssDeclarationRulesDictionaryToCss, decrement, decrementBy, delayPromise, dictToEntries, dictToList, divideBy, ellipsis, ensureArray, ensureDefined, ensureNegativeNumber, ensureNonNegativeNumber, ensureNonPositiveNumber, ensurePositiveNumber, ensureReadableArray, entriesToDict, entriesToEntries, entriesToList, extendArray, extendArrayWith, fill, fillWith, filterMap, filterMapReduce, filterWithTypePredicate, findInArray, findIndexInArray, first$1 as first, flatMapTruthys, getCauseMessageFromError, getCauseStackFromError, getMessageFromError, getStackFromError, groupByBoolean, groupByBooleanWith, groupByNumber, groupByNumberWith, groupByString, groupByStringWith, groupBySymbol, groupBySymbolWith, hashCode, havingMaxBy, havingMinBy, head, identity, ifDefined, ifNullOrUndefined, iff, includes, increment, incrementBy, indexByNumber, indexByNumberWith, indexByString, indexByStringWith, indexBySymbol, indexBySymbolWith, indexByWith, isAllowedTimeDuration, isArray, isDefined, isEmpty, isError, isFalse, isFunction, isNegativeNumber, isNullOrUndefined, isNullOrUndefinedOrEmpty, isNumber, isPositiveNumber, isString, isTimeInstant, isTrue, isUpgradable, isZero, jsonCloneDeep, last$1 as last, listToDict, mapDefined, mapFirstTruthy, mapTruthys, max, maxBy, min, minBy, multiplyBy, noop, not, omitFromJsonObject, or, pad, padLeft, padRight, parseJson, parseTimeInstantBasicComponents, parseTimeInstantComponents, partition, pick, pipedInvoke, pipedInvokeFromArray, pluralize, promiseSequence, randomDecimalInInterval, randomId, randomIntegerInInterval, randomNumberInInterval, randomPick, randomPicks, range, repeat, reverse$1 as reverse, round, roundAwayFromZero, roundToLower, roundToNearest, roundToUpper, roundTowardsZero, shallowArrayEquals, shallowRecordEquals, sortedArray, splitWords, stringToNumber, stringifyJson, sum, sumBy, tail, throttle, throwIfNullOrUndefined, transformCssDictionary, tryToParseJson, tryToParseNumber, uniq, uniqBy, uniqByKey, unzip, upsert, withTryCatch, withTryCatchAsync, wrapWithString, xor, zip };
4114
4059
  //# sourceMappingURL=index.mjs.map