ts-data-forge 1.0.0 → 1.0.2
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/README.md +1 -1
- package/dist/array/array-utils.d.mts +2617 -0
- package/dist/array/array-utils.d.mts.map +1 -0
- package/dist/array/array-utils.mjs +2915 -0
- package/dist/array/array-utils.mjs.map +1 -0
- package/dist/array/index.d.mts +3 -0
- package/dist/array/index.d.mts.map +1 -0
- package/dist/array/index.mjs +3 -0
- package/dist/array/index.mjs.map +1 -0
- package/dist/array/tuple-utils.d.mts +421 -0
- package/dist/array/tuple-utils.d.mts.map +1 -0
- package/dist/array/tuple-utils.mjs +391 -0
- package/dist/array/tuple-utils.mjs.map +1 -0
- package/dist/collections/imap-mapped.d.mts +445 -0
- package/dist/collections/imap-mapped.d.mts.map +1 -0
- package/dist/collections/imap-mapped.mjs +424 -0
- package/dist/collections/imap-mapped.mjs.map +1 -0
- package/dist/collections/imap.d.mts +359 -0
- package/dist/collections/imap.d.mts.map +1 -0
- package/dist/collections/imap.mjs +338 -0
- package/dist/collections/imap.mjs.map +1 -0
- package/dist/collections/index.d.mts +7 -0
- package/dist/collections/index.d.mts.map +1 -0
- package/dist/collections/index.mjs +7 -0
- package/dist/collections/index.mjs.map +1 -0
- package/dist/collections/iset-mapped.d.mts +576 -0
- package/dist/collections/iset-mapped.d.mts.map +1 -0
- package/dist/collections/iset-mapped.mjs +522 -0
- package/dist/collections/iset-mapped.mjs.map +1 -0
- package/dist/collections/iset.d.mts +426 -0
- package/dist/collections/iset.d.mts.map +1 -0
- package/dist/collections/iset.mjs +437 -0
- package/dist/collections/iset.mjs.map +1 -0
- package/dist/collections/queue.d.mts +190 -0
- package/dist/collections/queue.d.mts.map +1 -0
- package/dist/collections/queue.mjs +317 -0
- package/dist/collections/queue.mjs.map +1 -0
- package/dist/collections/stack.d.mts +210 -0
- package/dist/collections/stack.d.mts.map +1 -0
- package/dist/collections/stack.mjs +353 -0
- package/dist/collections/stack.mjs.map +1 -0
- package/dist/expect-type.d.mts +199 -0
- package/dist/expect-type.d.mts.map +1 -0
- package/dist/expect-type.mjs +201 -0
- package/dist/expect-type.mjs.map +1 -0
- package/dist/functional/index.d.mts +5 -0
- package/dist/functional/index.d.mts.map +1 -0
- package/dist/functional/index.mjs +5 -0
- package/dist/functional/index.mjs.map +1 -0
- package/dist/functional/match.d.mts +215 -0
- package/dist/functional/match.d.mts.map +1 -0
- package/dist/functional/match.mjs +139 -0
- package/dist/functional/match.mjs.map +1 -0
- package/dist/functional/optional.d.mts +517 -0
- package/dist/functional/optional.d.mts.map +1 -0
- package/dist/functional/optional.mjs +532 -0
- package/dist/functional/optional.mjs.map +1 -0
- package/dist/functional/pipe.d.mts +185 -0
- package/dist/functional/pipe.d.mts.map +1 -0
- package/dist/functional/pipe.mjs +129 -0
- package/dist/functional/pipe.mjs.map +1 -0
- package/dist/functional/result.d.mts +796 -0
- package/dist/functional/result.d.mts.map +1 -0
- package/dist/functional/result.mjs +844 -0
- package/dist/functional/result.mjs.map +1 -0
- package/dist/globals.d.mts +38 -0
- package/dist/guard/has-key.d.mts +100 -0
- package/dist/guard/has-key.d.mts.map +1 -0
- package/dist/guard/has-key.mjs +94 -0
- package/dist/guard/has-key.mjs.map +1 -0
- package/dist/guard/index.d.mts +8 -0
- package/dist/guard/index.d.mts.map +1 -0
- package/dist/guard/index.mjs +8 -0
- package/dist/guard/index.mjs.map +1 -0
- package/dist/guard/is-non-empty-string.d.mts +106 -0
- package/dist/guard/is-non-empty-string.d.mts.map +1 -0
- package/dist/guard/is-non-empty-string.mjs +108 -0
- package/dist/guard/is-non-empty-string.mjs.map +1 -0
- package/dist/guard/is-non-null-object.d.mts +105 -0
- package/dist/guard/is-non-null-object.d.mts.map +1 -0
- package/dist/guard/is-non-null-object.mjs +108 -0
- package/dist/guard/is-non-null-object.mjs.map +1 -0
- package/dist/guard/is-primitive.d.mts +146 -0
- package/dist/guard/is-primitive.d.mts.map +1 -0
- package/dist/guard/is-primitive.mjs +161 -0
- package/dist/guard/is-primitive.mjs.map +1 -0
- package/dist/guard/is-record.d.mts +151 -0
- package/dist/guard/is-record.d.mts.map +1 -0
- package/dist/guard/is-record.mjs +155 -0
- package/dist/guard/is-record.mjs.map +1 -0
- package/dist/guard/is-type.d.mts +430 -0
- package/dist/guard/is-type.d.mts.map +1 -0
- package/dist/guard/is-type.mjs +432 -0
- package/dist/guard/is-type.mjs.map +1 -0
- package/dist/guard/key-is-in.d.mts +158 -0
- package/dist/guard/key-is-in.d.mts.map +1 -0
- package/dist/guard/key-is-in.mjs +160 -0
- package/dist/guard/key-is-in.mjs.map +1 -0
- package/dist/index.d.mts +11 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +61 -0
- package/dist/index.mjs.map +1 -0
- package/dist/iterator/index.d.mts +2 -0
- package/dist/iterator/index.d.mts.map +1 -0
- package/dist/iterator/index.mjs +2 -0
- package/dist/iterator/index.mjs.map +1 -0
- package/dist/iterator/range.d.mts +97 -0
- package/dist/iterator/range.d.mts.map +1 -0
- package/dist/iterator/range.mjs +130 -0
- package/dist/iterator/range.mjs.map +1 -0
- package/dist/json/index.d.mts +2 -0
- package/dist/json/index.d.mts.map +1 -0
- package/dist/json/index.mjs +2 -0
- package/dist/json/index.mjs.map +1 -0
- package/dist/json/json.d.mts +597 -0
- package/dist/json/json.d.mts.map +1 -0
- package/dist/json/json.mjs +687 -0
- package/dist/json/json.mjs.map +1 -0
- package/dist/number/branded-types/finite-number.d.mts +291 -0
- package/dist/number/branded-types/finite-number.d.mts.map +1 -0
- package/dist/number/branded-types/finite-number.mjs +296 -0
- package/dist/number/branded-types/finite-number.mjs.map +1 -0
- package/dist/number/branded-types/index.d.mts +27 -0
- package/dist/number/branded-types/index.d.mts.map +1 -0
- package/dist/number/branded-types/index.mjs +27 -0
- package/dist/number/branded-types/index.mjs.map +1 -0
- package/dist/number/branded-types/int.d.mts +242 -0
- package/dist/number/branded-types/int.d.mts.map +1 -0
- package/dist/number/branded-types/int.mjs +239 -0
- package/dist/number/branded-types/int.mjs.map +1 -0
- package/dist/number/branded-types/int16.d.mts +162 -0
- package/dist/number/branded-types/int16.d.mts.map +1 -0
- package/dist/number/branded-types/int16.mjs +141 -0
- package/dist/number/branded-types/int16.mjs.map +1 -0
- package/dist/number/branded-types/int32.d.mts +155 -0
- package/dist/number/branded-types/int32.d.mts.map +1 -0
- package/dist/number/branded-types/int32.mjs +142 -0
- package/dist/number/branded-types/int32.mjs.map +1 -0
- package/dist/number/branded-types/non-negative-finite-number.d.mts +165 -0
- package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -0
- package/dist/number/branded-types/non-negative-finite-number.mjs +160 -0
- package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -0
- package/dist/number/branded-types/non-negative-int16.d.mts +160 -0
- package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -0
- package/dist/number/branded-types/non-negative-int16.mjs +138 -0
- package/dist/number/branded-types/non-negative-int16.mjs.map +1 -0
- package/dist/number/branded-types/non-negative-int32.d.mts +156 -0
- package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -0
- package/dist/number/branded-types/non-negative-int32.mjs +138 -0
- package/dist/number/branded-types/non-negative-int32.mjs.map +1 -0
- package/dist/number/branded-types/non-zero-finite-number.d.mts +154 -0
- package/dist/number/branded-types/non-zero-finite-number.d.mts.map +1 -0
- package/dist/number/branded-types/non-zero-finite-number.mjs +160 -0
- package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -0
- package/dist/number/branded-types/non-zero-int.d.mts +131 -0
- package/dist/number/branded-types/non-zero-int.d.mts.map +1 -0
- package/dist/number/branded-types/non-zero-int.mjs +128 -0
- package/dist/number/branded-types/non-zero-int.mjs.map +1 -0
- package/dist/number/branded-types/non-zero-int16.d.mts +166 -0
- package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -0
- package/dist/number/branded-types/non-zero-int16.mjs +145 -0
- package/dist/number/branded-types/non-zero-int16.mjs.map +1 -0
- package/dist/number/branded-types/non-zero-int32.d.mts +158 -0
- package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -0
- package/dist/number/branded-types/non-zero-int32.mjs +145 -0
- package/dist/number/branded-types/non-zero-int32.mjs.map +1 -0
- package/dist/number/branded-types/non-zero-safe-int.d.mts +148 -0
- package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -0
- package/dist/number/branded-types/non-zero-safe-int.mjs +145 -0
- package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -0
- package/dist/number/branded-types/non-zero-uint16.d.mts +160 -0
- package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -0
- package/dist/number/branded-types/non-zero-uint16.mjs +140 -0
- package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -0
- package/dist/number/branded-types/non-zero-uint32.d.mts +156 -0
- package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -0
- package/dist/number/branded-types/non-zero-uint32.mjs +140 -0
- package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -0
- package/dist/number/branded-types/positive-finite-number.d.mts +171 -0
- package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -0
- package/dist/number/branded-types/positive-finite-number.mjs +165 -0
- package/dist/number/branded-types/positive-finite-number.mjs.map +1 -0
- package/dist/number/branded-types/positive-int.d.mts +270 -0
- package/dist/number/branded-types/positive-int.d.mts.map +1 -0
- package/dist/number/branded-types/positive-int.mjs +257 -0
- package/dist/number/branded-types/positive-int.mjs.map +1 -0
- package/dist/number/branded-types/positive-int16.d.mts +162 -0
- package/dist/number/branded-types/positive-int16.d.mts.map +1 -0
- package/dist/number/branded-types/positive-int16.mjs +139 -0
- package/dist/number/branded-types/positive-int16.mjs.map +1 -0
- package/dist/number/branded-types/positive-int32.d.mts +158 -0
- package/dist/number/branded-types/positive-int32.d.mts.map +1 -0
- package/dist/number/branded-types/positive-int32.mjs +139 -0
- package/dist/number/branded-types/positive-int32.mjs.map +1 -0
- package/dist/number/branded-types/positive-safe-int.d.mts +152 -0
- package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -0
- package/dist/number/branded-types/positive-safe-int.mjs +138 -0
- package/dist/number/branded-types/positive-safe-int.mjs.map +1 -0
- package/dist/number/branded-types/positive-uint16.d.mts +160 -0
- package/dist/number/branded-types/positive-uint16.d.mts.map +1 -0
- package/dist/number/branded-types/positive-uint16.mjs +139 -0
- package/dist/number/branded-types/positive-uint16.mjs.map +1 -0
- package/dist/number/branded-types/positive-uint32.d.mts +156 -0
- package/dist/number/branded-types/positive-uint32.d.mts.map +1 -0
- package/dist/number/branded-types/positive-uint32.mjs +139 -0
- package/dist/number/branded-types/positive-uint32.mjs.map +1 -0
- package/dist/number/branded-types/safe-int.d.mts +243 -0
- package/dist/number/branded-types/safe-int.d.mts.map +1 -0
- package/dist/number/branded-types/safe-int.mjs +240 -0
- package/dist/number/branded-types/safe-int.mjs.map +1 -0
- package/dist/number/branded-types/safe-uint.d.mts +151 -0
- package/dist/number/branded-types/safe-uint.d.mts.map +1 -0
- package/dist/number/branded-types/safe-uint.mjs +138 -0
- package/dist/number/branded-types/safe-uint.mjs.map +1 -0
- package/dist/number/branded-types/uint.d.mts +144 -0
- package/dist/number/branded-types/uint.d.mts.map +1 -0
- package/dist/number/branded-types/uint.mjs +132 -0
- package/dist/number/branded-types/uint.mjs.map +1 -0
- package/dist/number/branded-types/uint16.d.mts +157 -0
- package/dist/number/branded-types/uint16.d.mts.map +1 -0
- package/dist/number/branded-types/uint16.mjs +137 -0
- package/dist/number/branded-types/uint16.mjs.map +1 -0
- package/dist/number/branded-types/uint32.d.mts +185 -0
- package/dist/number/branded-types/uint32.d.mts.map +1 -0
- package/dist/number/branded-types/uint32.mjs +169 -0
- package/dist/number/branded-types/uint32.mjs.map +1 -0
- package/dist/number/enum/index.d.mts +3 -0
- package/dist/number/enum/index.d.mts.map +1 -0
- package/dist/number/enum/index.mjs +3 -0
- package/dist/number/enum/index.mjs.map +1 -0
- package/dist/number/enum/int8.d.mts +202 -0
- package/dist/number/enum/int8.d.mts.map +1 -0
- package/dist/number/enum/int8.mjs +296 -0
- package/dist/number/enum/int8.mjs.map +1 -0
- package/dist/number/enum/uint8.d.mts +128 -0
- package/dist/number/enum/uint8.d.mts.map +1 -0
- package/dist/number/enum/uint8.mjs +251 -0
- package/dist/number/enum/uint8.mjs.map +1 -0
- package/dist/number/index.d.mts +5 -0
- package/dist/number/index.d.mts.map +1 -0
- package/dist/number/index.mjs +31 -0
- package/dist/number/index.mjs.map +1 -0
- package/dist/number/num.d.mts +515 -0
- package/dist/number/num.d.mts.map +1 -0
- package/dist/number/num.mjs +513 -0
- package/dist/number/num.mjs.map +1 -0
- package/dist/number/refined-number-utils.d.mts +191 -0
- package/dist/number/refined-number-utils.d.mts.map +1 -0
- package/dist/number/refined-number-utils.mjs +179 -0
- package/dist/number/refined-number-utils.mjs.map +1 -0
- package/dist/object/index.d.mts +2 -0
- package/dist/object/index.d.mts.map +1 -0
- package/dist/object/index.mjs +2 -0
- package/dist/object/index.mjs.map +1 -0
- package/dist/object/object.d.mts +296 -0
- package/dist/object/object.d.mts.map +1 -0
- package/dist/object/object.mjs +295 -0
- package/dist/object/object.mjs.map +1 -0
- package/dist/others/cast-mutable.d.mts +110 -0
- package/dist/others/cast-mutable.d.mts.map +1 -0
- package/dist/others/cast-mutable.mjs +114 -0
- package/dist/others/cast-mutable.mjs.map +1 -0
- package/dist/others/cast-readonly.d.mts +189 -0
- package/dist/others/cast-readonly.d.mts.map +1 -0
- package/dist/others/cast-readonly.mjs +193 -0
- package/dist/others/cast-readonly.mjs.map +1 -0
- package/dist/others/if-then.d.mts +98 -0
- package/dist/others/if-then.d.mts.map +1 -0
- package/dist/others/if-then.mjs +100 -0
- package/dist/others/if-then.mjs.map +1 -0
- package/dist/others/index.d.mts +8 -0
- package/dist/others/index.d.mts.map +1 -0
- package/dist/others/index.mjs +8 -0
- package/dist/others/index.mjs.map +1 -0
- package/dist/others/map-nullable.d.mts +151 -0
- package/dist/others/map-nullable.d.mts.map +1 -0
- package/dist/others/map-nullable.mjs +159 -0
- package/dist/others/map-nullable.mjs.map +1 -0
- package/dist/others/memoize-function.d.mts +173 -0
- package/dist/others/memoize-function.d.mts.map +1 -0
- package/dist/others/memoize-function.mjs +189 -0
- package/dist/others/memoize-function.mjs.map +1 -0
- package/dist/others/tuple.d.mts +159 -0
- package/dist/others/tuple.d.mts.map +1 -0
- package/dist/others/tuple.mjs +161 -0
- package/dist/others/tuple.mjs.map +1 -0
- package/dist/others/unknown-to-string.d.mts +180 -0
- package/dist/others/unknown-to-string.d.mts.map +1 -0
- package/dist/others/unknown-to-string.mjs +211 -0
- package/dist/others/unknown-to-string.mjs.map +1 -0
- package/dist/tsconfig.json +1 -0
- package/package.json +18 -16
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
import { isRecord } from '../guard/is-record.mjs';
|
|
2
|
+
import { pipe } from './pipe.mjs';
|
|
3
|
+
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-unsafe-type-assertion */
|
|
5
|
+
/** @internal Symbol to identify the 'Some' variant of Optional. */
|
|
6
|
+
const SomeTypeSymbol = Symbol('Optional.some');
|
|
7
|
+
/** @internal Symbol to identify the 'None' variant of Optional. */
|
|
8
|
+
const NoneTypeSymbol = Symbol('Optional.none');
|
|
9
|
+
/**
|
|
10
|
+
* Namespace for the {@link Optional} type and related functions.
|
|
11
|
+
* Provides utilities to handle values that might be absent, similar to Option types in other languages.
|
|
12
|
+
*/
|
|
13
|
+
var Optional;
|
|
14
|
+
(function (Optional) {
|
|
15
|
+
/**
|
|
16
|
+
* Checks if the given value is an {@link Optional}.
|
|
17
|
+
* @param maybeOptional The value to check.
|
|
18
|
+
* @returns `true` if the value is an {@link Optional}, otherwise `false`.
|
|
19
|
+
*/
|
|
20
|
+
Optional.isOptional = (maybeOptional) => isRecord(maybeOptional) &&
|
|
21
|
+
Object.hasOwn(maybeOptional, 'type') &&
|
|
22
|
+
((maybeOptional['type'] === SomeTypeSymbol &&
|
|
23
|
+
Object.hasOwn(maybeOptional, 'value')) ||
|
|
24
|
+
maybeOptional['type'] === NoneTypeSymbol);
|
|
25
|
+
/**
|
|
26
|
+
* Creates an {@link Optional.Some} containing the given value.
|
|
27
|
+
* @template S The type of the value.
|
|
28
|
+
* @param value The value to wrap in an {@link Optional.Some}.
|
|
29
|
+
* @returns An {@link Optional.Some}<S> containing the value.
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const someValue = Optional.some(42);
|
|
33
|
+
* const someString = Optional.some("hello");
|
|
34
|
+
* const someObject = Optional.some({ name: "Alice", age: 30 });
|
|
35
|
+
*
|
|
36
|
+
* console.log(Optional.isSome(someValue)); // true
|
|
37
|
+
* console.log(Optional.unwrap(someValue)); // 42
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
Optional.some = (value) => ({
|
|
41
|
+
type: SomeTypeSymbol,
|
|
42
|
+
value,
|
|
43
|
+
});
|
|
44
|
+
/**
|
|
45
|
+
* The singleton instance representing {@link Optional.None} (an empty Optional).
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const emptyValue = Optional.none;
|
|
49
|
+
*
|
|
50
|
+
* console.log(Optional.isNone(emptyValue)); // true
|
|
51
|
+
* console.log(Optional.unwrap(emptyValue)); // undefined
|
|
52
|
+
* console.log(Optional.unwrapOr(emptyValue, "default")); // "default"
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
Optional.none = { type: NoneTypeSymbol };
|
|
56
|
+
/**
|
|
57
|
+
* Checks if an {@link Optional} is {@link Optional.Some}.
|
|
58
|
+
* Acts as a type guard.
|
|
59
|
+
* @template O The {@link Optional.Base} type to check.
|
|
60
|
+
* @param optional The {@link Optional} to check.
|
|
61
|
+
* @returns `true` if the {@link Optional} is {@link Optional.Some}, `false` otherwise.
|
|
62
|
+
*/
|
|
63
|
+
Optional.isSome = (optional) => optional.type === SomeTypeSymbol;
|
|
64
|
+
/**
|
|
65
|
+
* Checks if an {@link Optional} is {@link Optional.None}.
|
|
66
|
+
* Acts as a type guard.
|
|
67
|
+
* @template O The {@link Optional.Base} type to check.
|
|
68
|
+
* @param optional The {@link Optional} to check.
|
|
69
|
+
* @returns `true` if the {@link Optional} is {@link Optional.None}, `false` otherwise.
|
|
70
|
+
*/
|
|
71
|
+
Optional.isNone = (optional) => optional.type === NoneTypeSymbol;
|
|
72
|
+
/**
|
|
73
|
+
* Unwraps an `Optional`, returning the contained value.
|
|
74
|
+
* Throws an error if the `Optional` is `Optional.None`.
|
|
75
|
+
*
|
|
76
|
+
* This is a safer alternative to direct value access when you know the Optional
|
|
77
|
+
* should contain a value. Use this method when an empty Optional represents
|
|
78
|
+
* a programming error or unexpected condition.
|
|
79
|
+
*
|
|
80
|
+
* @template O The `Optional.Base` type to unwrap.
|
|
81
|
+
* @param optional The `Optional` to unwrap.
|
|
82
|
+
* @returns The contained value if `Optional.Some`.
|
|
83
|
+
* @throws {Error} Error with message "`unwrapThrow()` has failed because it is `None`" if the `Optional` is `Optional.None`.
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* // Safe unwrapping when you know the value exists
|
|
87
|
+
* const config = loadConfig(); // returns Optional<Config>
|
|
88
|
+
* if (Optional.isSome(config)) {
|
|
89
|
+
* const value = Optional.unwrapThrow(config); // Safe to unwrap
|
|
90
|
+
* console.log(value); // Config object
|
|
91
|
+
* }
|
|
92
|
+
*
|
|
93
|
+
* // Unsafe unwrapping - will throw if empty
|
|
94
|
+
* const userInput = Optional.some(42);
|
|
95
|
+
* console.log(Optional.unwrapThrow(userInput)); // 42
|
|
96
|
+
*
|
|
97
|
+
* const empty = Optional.none;
|
|
98
|
+
* try {
|
|
99
|
+
* Optional.unwrapThrow(empty); // throws Error
|
|
100
|
+
* } catch (error) {
|
|
101
|
+
* console.log(error.message); // "`unwrapThrow()` has failed because it is `None`"
|
|
102
|
+
* }
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
Optional.unwrapThrow = (optional) => {
|
|
106
|
+
if (Optional.isSome(optional)) {
|
|
107
|
+
return optional.value;
|
|
108
|
+
}
|
|
109
|
+
throw new Error('`unwrapThrow()` has failed because it is `None`');
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Unwraps an `Optional`, returning the contained value or `undefined` if empty.
|
|
113
|
+
*
|
|
114
|
+
* This function provides a safe way to extract values from Optionals without
|
|
115
|
+
* throwing exceptions. It has overloaded behavior based on the type:
|
|
116
|
+
* - For `Optional.Some<T>`: Always returns `T` (guaranteed by type system)
|
|
117
|
+
* - For general `Optional<T>`: Returns `T | undefined`
|
|
118
|
+
*
|
|
119
|
+
* @template O The `Optional.Base` type to unwrap.
|
|
120
|
+
* @param optional The `Optional` to unwrap.
|
|
121
|
+
* @returns The contained value if `Optional.Some`, otherwise `undefined`.
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* // With Some - guaranteed to return value
|
|
125
|
+
* const some = Optional.some(42);
|
|
126
|
+
* const value = Optional.unwrap(some); // Type: number, Value: 42
|
|
127
|
+
*
|
|
128
|
+
* // With general Optional - may return undefined
|
|
129
|
+
* const maybeValue: Optional<string> = getOptionalString();
|
|
130
|
+
* const result = Optional.unwrap(maybeValue); // Type: string | undefined
|
|
131
|
+
*
|
|
132
|
+
* // Safe pattern for handling both cases
|
|
133
|
+
* const optional = Optional.some("hello");
|
|
134
|
+
* const unwrapped = Optional.unwrap(optional);
|
|
135
|
+
* if (unwrapped !== undefined) {
|
|
136
|
+
* console.log(unwrapped.toUpperCase()); // "HELLO"
|
|
137
|
+
* }
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
Optional.unwrap = ((optional) => Optional.isNone(optional)
|
|
141
|
+
? undefined
|
|
142
|
+
: optional.value);
|
|
143
|
+
/**
|
|
144
|
+
* Unwraps an `Optional`, returning the contained value or a default value if it's `Optional.None`.
|
|
145
|
+
*
|
|
146
|
+
* Supports both direct usage and curried form for functional composition.
|
|
147
|
+
* This is often preferred over `unwrap()` when you have a sensible fallback value.
|
|
148
|
+
*
|
|
149
|
+
* @template O The `Optional.Base` type to unwrap.
|
|
150
|
+
* @template D The type of the default value.
|
|
151
|
+
* @param optional The `Optional` to unwrap.
|
|
152
|
+
* @param defaultValue The value to return if `optional` is `Optional.None`.
|
|
153
|
+
* @returns The contained value if `Optional.Some`, otherwise `defaultValue`.
|
|
154
|
+
* @example
|
|
155
|
+
* ```typescript
|
|
156
|
+
* // Direct usage - most common pattern
|
|
157
|
+
* const userAge = Optional.fromNullable(user.age);
|
|
158
|
+
* const displayAge = Optional.unwrapOr(userAge, "Unknown");
|
|
159
|
+
* console.log(`Age: ${displayAge}`); // "Age: 25" or "Age: Unknown"
|
|
160
|
+
*
|
|
161
|
+
* // With different Optional types
|
|
162
|
+
* const some = Optional.some(42);
|
|
163
|
+
* const value1 = Optional.unwrapOr(some, 0);
|
|
164
|
+
* console.log(value1); // 42
|
|
165
|
+
*
|
|
166
|
+
* const none = Optional.none;
|
|
167
|
+
* const value2 = Optional.unwrapOr(none, 0);
|
|
168
|
+
* console.log(value2); // 0
|
|
169
|
+
*
|
|
170
|
+
* // Curried usage for functional composition
|
|
171
|
+
* const unwrapWithDefault = Optional.unwrapOr("default");
|
|
172
|
+
* const result = pipe(Optional.some("hello"))
|
|
173
|
+
* .map(unwrapWithDefault)
|
|
174
|
+
* .value;
|
|
175
|
+
* console.log(result); // "hello"
|
|
176
|
+
*
|
|
177
|
+
* // Chaining with other Optional operations
|
|
178
|
+
* const processValue = (input: string) =>
|
|
179
|
+
* pipe(Optional.fromNullable(input))
|
|
180
|
+
* .map(Optional.map(s => s.toUpperCase()))
|
|
181
|
+
* .map(Optional.unwrapOr("NO INPUT"))
|
|
182
|
+
* .value;
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
Optional.unwrapOr = ((...args) => {
|
|
186
|
+
switch (args.length) {
|
|
187
|
+
case 2: {
|
|
188
|
+
const [optional, defaultValue] = args;
|
|
189
|
+
return Optional.isNone(optional)
|
|
190
|
+
? defaultValue
|
|
191
|
+
: optional.value;
|
|
192
|
+
}
|
|
193
|
+
case 1: {
|
|
194
|
+
// Curried version: first argument is default value
|
|
195
|
+
const [defaultValue] = args;
|
|
196
|
+
return (optional) => Optional.unwrapOr(optional, defaultValue);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
/**
|
|
201
|
+
* Returns the `Optional` if it is `Some`, otherwise returns the alternative.
|
|
202
|
+
*
|
|
203
|
+
* Provides a way to chain Optional operations with fallback values. This is
|
|
204
|
+
* particularly useful for implementing default behavior or cascading lookups.
|
|
205
|
+
* Supports both direct usage and curried form for functional composition.
|
|
206
|
+
*
|
|
207
|
+
* @template O The input `Optional.Base` type.
|
|
208
|
+
* @param optional The `Optional` to check.
|
|
209
|
+
* @param alternative The alternative `Optional` to return if the first is `None`.
|
|
210
|
+
* @returns The first `Optional` if `Some`, otherwise the alternative.
|
|
211
|
+
* @example
|
|
212
|
+
* ```typescript
|
|
213
|
+
* // Direct usage - cascading lookups
|
|
214
|
+
* const primaryConfig = loadPrimaryConfig(); // Optional<Config>
|
|
215
|
+
* const fallbackConfig = loadFallbackConfig(); // Optional<Config>
|
|
216
|
+
* const config = Optional.orElse(primaryConfig, fallbackConfig);
|
|
217
|
+
*
|
|
218
|
+
* // Multiple fallbacks
|
|
219
|
+
* const userPreference = getUserPreference(); // Optional<string>
|
|
220
|
+
* const systemDefault = Optional.some("default-theme");
|
|
221
|
+
* const theme = Optional.orElse(userPreference, systemDefault);
|
|
222
|
+
* console.log(Optional.unwrap(theme)); // User's preference or "default-theme"
|
|
223
|
+
*
|
|
224
|
+
* // Regular usage example
|
|
225
|
+
* const primary = Optional.none;
|
|
226
|
+
* const fallback = Optional.some("default");
|
|
227
|
+
* const result = Optional.orElse(primary, fallback);
|
|
228
|
+
* console.log(Optional.unwrap(result)); // "default"
|
|
229
|
+
*
|
|
230
|
+
* // Curried usage for functional composition
|
|
231
|
+
* const withFallback = Optional.orElse(Optional.some("fallback"));
|
|
232
|
+
* const result2 = pipe(Optional.none)
|
|
233
|
+
* .map(withFallback)
|
|
234
|
+
* .value;
|
|
235
|
+
* console.log(Optional.unwrap(result2)); // "fallback"
|
|
236
|
+
*
|
|
237
|
+
* // Chaining multiple orElse operations
|
|
238
|
+
* const finalResult = pipe(Optional.none)
|
|
239
|
+
* .map(Optional.orElse(Optional.none)) // Still none
|
|
240
|
+
* .map(Optional.orElse(Optional.some("last resort")))
|
|
241
|
+
* .value;
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
Optional.orElse = ((...args) => {
|
|
245
|
+
switch (args.length) {
|
|
246
|
+
case 2: {
|
|
247
|
+
const [optional, alternative] = args;
|
|
248
|
+
return Optional.isNone(optional) ? alternative : optional;
|
|
249
|
+
}
|
|
250
|
+
case 1: {
|
|
251
|
+
const [alternative] = args;
|
|
252
|
+
return (optional) => Optional.orElse(optional, alternative);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
/**
|
|
257
|
+
* Maps an {@link Optional}<S> to {@link Optional}<S2> by applying a function to a contained value.
|
|
258
|
+
* If the {@link Optional} is {@link Optional.None}, it returns {@link Optional.none}.
|
|
259
|
+
* Otherwise, it applies the `mapFn` to the value in `Optional.Some` and returns a new `Optional.Some` with the result.
|
|
260
|
+
* @template O The input `Optional.Base` type.
|
|
261
|
+
* @template S2 The type of the value returned by the mapping function.
|
|
262
|
+
* @param optional The `Optional` to map.
|
|
263
|
+
* @param mapFn The function to apply to the value if it exists.
|
|
264
|
+
* @returns A new `Optional<S2>` resulting from the mapping, or `Optional.None` if the input was `Optional.None`.
|
|
265
|
+
* @example
|
|
266
|
+
* ```typescript
|
|
267
|
+
* const someNumber = Optional.some(5);
|
|
268
|
+
* const mapped = Optional.map(someNumber, x => x * 2);
|
|
269
|
+
* console.log(Optional.unwrap(mapped)); // 10
|
|
270
|
+
*
|
|
271
|
+
* const noneValue = Optional.none;
|
|
272
|
+
* const mappedNone = Optional.map(noneValue, x => x * 2);
|
|
273
|
+
* console.log(Optional.isNone(mappedNone)); // true
|
|
274
|
+
*
|
|
275
|
+
* // Chaining maps
|
|
276
|
+
* const result = Optional.map(
|
|
277
|
+
* Optional.map(Optional.some("hello"), s => s.toUpperCase()),
|
|
278
|
+
* s => s.length
|
|
279
|
+
* );
|
|
280
|
+
* console.log(Optional.unwrap(result)); // 5
|
|
281
|
+
*
|
|
282
|
+
* // Curried version for use with pipe
|
|
283
|
+
* const doubler = Optional.map((x: number) => x * 2);
|
|
284
|
+
* const result2 = pipe(Optional.some(5)).map(doubler).value;
|
|
285
|
+
* console.log(Optional.unwrap(result2)); // 10
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
Optional.map = ((...args) => {
|
|
289
|
+
switch (args.length) {
|
|
290
|
+
case 2: {
|
|
291
|
+
const [optional, mapFn] = args;
|
|
292
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
293
|
+
return Optional.isSome(optional) ? Optional.some(mapFn(Optional.unwrap(optional))) : Optional.none;
|
|
294
|
+
}
|
|
295
|
+
case 1: {
|
|
296
|
+
// Curried version: first argument is mapping function
|
|
297
|
+
const [mapFn] = args;
|
|
298
|
+
return (optional) => Optional.map(optional, mapFn);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
/**
|
|
303
|
+
* Applies a function that returns an `Optional` to the value in an `Optional.Some`.
|
|
304
|
+
* If the input is `Optional.None`, returns `Optional.None`.
|
|
305
|
+
* This is the monadic bind operation for `Optional`.
|
|
306
|
+
* @template O The input `Optional.Base` type.
|
|
307
|
+
* @template S2 The value type of the `Optional` returned by the function.
|
|
308
|
+
* @param optional The `Optional` to flat map.
|
|
309
|
+
* @param flatMapFn The function to apply that returns an `Optional`.
|
|
310
|
+
* @returns The result of applying the function, or `Optional.None`.
|
|
311
|
+
* @example
|
|
312
|
+
* ```typescript
|
|
313
|
+
* // Regular usage
|
|
314
|
+
* const parseNumber = (s: string): Optional<number> => {
|
|
315
|
+
* const n = Number(s);
|
|
316
|
+
* return isNaN(n) ? Optional.none : Optional.some(n);
|
|
317
|
+
* };
|
|
318
|
+
*
|
|
319
|
+
* const result = Optional.flatMap(Optional.some("42"), parseNumber);
|
|
320
|
+
* console.log(Optional.unwrap(result)); // 42
|
|
321
|
+
*
|
|
322
|
+
* // Curried usage for pipe composition
|
|
323
|
+
* const parser = Optional.flatMap(parseNumber);
|
|
324
|
+
* const result2 = pipe(Optional.some("42")).map(parser).value;
|
|
325
|
+
* console.log(Optional.unwrap(result2)); // 42
|
|
326
|
+
* ```
|
|
327
|
+
*/
|
|
328
|
+
Optional.flatMap = ((...args) => {
|
|
329
|
+
switch (args.length) {
|
|
330
|
+
case 2: {
|
|
331
|
+
const [optional, flatMapFn] = args;
|
|
332
|
+
return Optional.isSome(optional) ? flatMapFn(Optional.unwrap(optional)) : Optional.none;
|
|
333
|
+
}
|
|
334
|
+
case 1: {
|
|
335
|
+
const [flatMapFn] = args;
|
|
336
|
+
return (optional) => Optional.flatMap(optional, flatMapFn);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
/**
|
|
341
|
+
* Filters an `Optional` based on a predicate.
|
|
342
|
+
* If the `Optional` is `Some` and the predicate returns true, returns the original `Optional`.
|
|
343
|
+
* Otherwise returns `None`.
|
|
344
|
+
* @template O The input `Optional.Base` type.
|
|
345
|
+
* @param optional The `Optional` to filter.
|
|
346
|
+
* @param predicate The predicate function.
|
|
347
|
+
* @returns The filtered `Optional`.
|
|
348
|
+
* @example
|
|
349
|
+
* ```typescript
|
|
350
|
+
* // Regular usage
|
|
351
|
+
* const someEven = Optional.some(4);
|
|
352
|
+
* const filtered = Optional.filter(someEven, x => x % 2 === 0);
|
|
353
|
+
* console.log(Optional.unwrap(filtered)); // 4
|
|
354
|
+
*
|
|
355
|
+
* // Curried usage for pipe composition
|
|
356
|
+
* const evenFilter = Optional.filter((x: number) => x % 2 === 0);
|
|
357
|
+
* const result = pipe(Optional.some(4)).map(evenFilter).value;
|
|
358
|
+
* console.log(Optional.unwrap(result)); // 4
|
|
359
|
+
* ```
|
|
360
|
+
*/
|
|
361
|
+
Optional.filter = ((...args) => {
|
|
362
|
+
switch (args.length) {
|
|
363
|
+
case 2: {
|
|
364
|
+
const [optional, predicate] = args;
|
|
365
|
+
return Optional.isSome(optional)
|
|
366
|
+
? pipe(Optional.unwrap(optional)).map((value) => predicate(value) ? Optional.some(value) : Optional.none).value
|
|
367
|
+
: Optional.none;
|
|
368
|
+
}
|
|
369
|
+
case 1: {
|
|
370
|
+
// Curried version: first argument is predicate function
|
|
371
|
+
const [predicate] = args;
|
|
372
|
+
return (optional) => Optional.filter(optional, predicate);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
/**
|
|
377
|
+
* Unwraps an `Optional`, returning the contained value or throwing an error with the provided message.
|
|
378
|
+
* @template O The `Optional.Base` type to unwrap.
|
|
379
|
+
* @param optional The `Optional` to unwrap.
|
|
380
|
+
* @param message The error message to throw if the `Optional` is `Optional.None`.
|
|
381
|
+
* @returns The contained value if `Optional.Some`.
|
|
382
|
+
* @throws Error with the provided message if the `Optional` is `Optional.None`.
|
|
383
|
+
* @example
|
|
384
|
+
* ```typescript
|
|
385
|
+
* // Regular usage
|
|
386
|
+
* const some = Optional.some(42);
|
|
387
|
+
* const value = Optional.expectToBe(some, "Value must exist");
|
|
388
|
+
* console.log(value); // 42
|
|
389
|
+
*
|
|
390
|
+
* // Curried usage for pipe composition
|
|
391
|
+
* const getValue = Optional.expectToBe("Value must exist");
|
|
392
|
+
* const value2 = pipe(Optional.some(42)).map(getValue).value;
|
|
393
|
+
* console.log(value2); // 42
|
|
394
|
+
* ```
|
|
395
|
+
*/
|
|
396
|
+
Optional.expectToBe = ((...args) => {
|
|
397
|
+
switch (args.length) {
|
|
398
|
+
case 2: {
|
|
399
|
+
const [optional, message] = args;
|
|
400
|
+
if (Optional.isSome(optional)) {
|
|
401
|
+
return Optional.unwrap(optional);
|
|
402
|
+
}
|
|
403
|
+
throw new Error(message);
|
|
404
|
+
}
|
|
405
|
+
case 1: {
|
|
406
|
+
// Curried version: first argument is message
|
|
407
|
+
const [message] = args;
|
|
408
|
+
return (optional) => Optional.expectToBe(optional, message);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
/**
|
|
413
|
+
* Combines two `Optional` values into a single `Optional` containing a tuple.
|
|
414
|
+
* If either `Optional` is `None`, returns `None`.
|
|
415
|
+
* @template A The value type of the first `Optional`.
|
|
416
|
+
* @template B The value type of the second `Optional`.
|
|
417
|
+
* @param optionalA The first `Optional`.
|
|
418
|
+
* @param optionalB The second `Optional`.
|
|
419
|
+
* @returns An `Optional` containing a tuple of both values, or `None`.
|
|
420
|
+
* @example
|
|
421
|
+
* ```typescript
|
|
422
|
+
* const a = Optional.some(1);
|
|
423
|
+
* const b = Optional.some("hello");
|
|
424
|
+
* const zipped = Optional.zip(a, b);
|
|
425
|
+
* console.log(Optional.unwrap(zipped)); // [1, "hello"]
|
|
426
|
+
*
|
|
427
|
+
* const withNone = Optional.zip(a, Optional.none);
|
|
428
|
+
* console.log(Optional.isNone(withNone)); // true
|
|
429
|
+
* ```
|
|
430
|
+
*/
|
|
431
|
+
Optional.zip = (optionalA, optionalB) => Optional.isSome(optionalA) && Optional.isSome(optionalB)
|
|
432
|
+
? Optional.some([optionalA.value, optionalB.value])
|
|
433
|
+
: Optional.none;
|
|
434
|
+
/**
|
|
435
|
+
* Converts a nullable value to an `Optional`.
|
|
436
|
+
*
|
|
437
|
+
* This is the primary way to lift nullable values (null or undefined) into
|
|
438
|
+
* the Optional type system. The function treats both `null` and `undefined`
|
|
439
|
+
* as empty values, converting them to `Optional.None`.
|
|
440
|
+
*
|
|
441
|
+
* @template T The type of the nullable value.
|
|
442
|
+
* @param value The nullable value to convert.
|
|
443
|
+
* @returns `Optional.Some<NonNullable<T>>` if the value is not null or undefined, otherwise `Optional.None`.
|
|
444
|
+
* @example
|
|
445
|
+
* ```typescript
|
|
446
|
+
* // Basic nullable conversion
|
|
447
|
+
* const value: string | null = "hello";
|
|
448
|
+
* const optional = Optional.fromNullable(value);
|
|
449
|
+
* console.log(Optional.unwrap(optional)); // "hello"
|
|
450
|
+
* console.log(Optional.isSome(optional)); // true
|
|
451
|
+
*
|
|
452
|
+
* // Handling null values
|
|
453
|
+
* const nullValue: string | null = null;
|
|
454
|
+
* const noneOptional = Optional.fromNullable(nullValue);
|
|
455
|
+
* console.log(Optional.isNone(noneOptional)); // true
|
|
456
|
+
*
|
|
457
|
+
* // Handling undefined values
|
|
458
|
+
* const undefinedValue: number | undefined = undefined;
|
|
459
|
+
* const alsoNone = Optional.fromNullable(undefinedValue);
|
|
460
|
+
* console.log(Optional.isNone(alsoNone)); // true
|
|
461
|
+
*
|
|
462
|
+
* // Common use case with API responses
|
|
463
|
+
* interface User {
|
|
464
|
+
* name: string;
|
|
465
|
+
* email?: string; // Optional field
|
|
466
|
+
* }
|
|
467
|
+
*
|
|
468
|
+
* const user: User = { name: "John" };
|
|
469
|
+
* const email = Optional.fromNullable(user.email);
|
|
470
|
+
* const emailDisplay = Optional.unwrapOr(email, "No email provided");
|
|
471
|
+
* console.log(emailDisplay); // "No email provided"
|
|
472
|
+
*
|
|
473
|
+
* // Chaining with other Optional operations
|
|
474
|
+
* const processNullableInput = (input: string | null) =>
|
|
475
|
+
* Optional.fromNullable(input)
|
|
476
|
+
* .map(Optional.map(s => s.trim()))
|
|
477
|
+
* .map(Optional.filter(s => s.length > 0))
|
|
478
|
+
* .map(Optional.unwrapOr("empty input"));
|
|
479
|
+
* ```
|
|
480
|
+
*/
|
|
481
|
+
Optional.fromNullable = (value) => (value == null ? Optional.none : Optional.some(value));
|
|
482
|
+
/**
|
|
483
|
+
* Converts an `Optional` to a nullable value.
|
|
484
|
+
*
|
|
485
|
+
* This function extracts the value from an Optional, returning `undefined`
|
|
486
|
+
* for empty Optionals. This is useful when interfacing with APIs or systems
|
|
487
|
+
* that expect nullable values rather than Optional types.
|
|
488
|
+
*
|
|
489
|
+
* Note: This returns `undefined` (not `null`) for consistency with JavaScript's
|
|
490
|
+
* undefined semantics and TypeScript's optional properties.
|
|
491
|
+
*
|
|
492
|
+
* @template O The `Optional.Base` type to convert.
|
|
493
|
+
* @param optional The `Optional` to convert.
|
|
494
|
+
* @returns The contained value if `Some`, otherwise `undefined`.
|
|
495
|
+
* @example
|
|
496
|
+
* ```typescript
|
|
497
|
+
* // Basic conversion
|
|
498
|
+
* const some = Optional.some(42);
|
|
499
|
+
* console.log(Optional.toNullable(some)); // 42
|
|
500
|
+
*
|
|
501
|
+
* const none = Optional.none;
|
|
502
|
+
* console.log(Optional.toNullable(none)); // undefined
|
|
503
|
+
*
|
|
504
|
+
* // Interface with nullable APIs
|
|
505
|
+
* interface ApiResponse {
|
|
506
|
+
* data?: string;
|
|
507
|
+
* }
|
|
508
|
+
*
|
|
509
|
+
* const optionalData: Optional<string> = processData();
|
|
510
|
+
* const response: ApiResponse = {
|
|
511
|
+
* data: Optional.toNullable(optionalData)
|
|
512
|
+
* };
|
|
513
|
+
*
|
|
514
|
+
* // Converting back and forth
|
|
515
|
+
* const original: string | undefined = getValue();
|
|
516
|
+
* const optional = Optional.fromNullable(original);
|
|
517
|
+
* const processed = Optional.map(optional, s => s.toUpperCase());
|
|
518
|
+
* const result: string | undefined = Optional.toNullable(processed);
|
|
519
|
+
*
|
|
520
|
+
* // Useful in conditional logic
|
|
521
|
+
* const maybeUser = findUser(id);
|
|
522
|
+
* const userName = Optional.toNullable(maybeUser);
|
|
523
|
+
* if (userName !== undefined) {
|
|
524
|
+
* console.log(`Found user: ${userName}`);
|
|
525
|
+
* }
|
|
526
|
+
* ```
|
|
527
|
+
*/
|
|
528
|
+
Optional.toNullable = (optional) => (Optional.isSome(optional) ? Optional.unwrap(optional) : undefined);
|
|
529
|
+
})(Optional || (Optional = {}));
|
|
530
|
+
|
|
531
|
+
export { Optional };
|
|
532
|
+
//# sourceMappingURL=optional.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optional.mjs","sources":["../../src/functional/optional.mts"],"sourcesContent":[null],"names":[],"mappings":";;;AAAA;AAIA;AACA,MAAM,cAAc,GAAkB,MAAM,CAAC,eAAe,CAAC;AAE7D;AACA,MAAM,cAAc,GAAkB,MAAM,CAAC,eAAe,CAAC;AA6B7D;;;AAGG;AACG,IAAW;AAAjB,CAAA,UAAiB,QAAQ,EAAA;AACvB;;;;AAIG;IACU,QAAA,CAAA,UAAU,GAAG,CACxB,aAAsB,KAEtB,QAAQ,CAAC,aAAa,CAAC;AACvB,QAAA,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC;AACpC,SAAC,CAAC,aAAa,CAAC,MAAM,CAAC,KAAK,cAAc;AACxC,YAAA,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,OAAO,CAAC;AACrC,YAAA,aAAa,CAAC,MAAM,CAAC,KAAK,cAAc,CAAC;AAwC7C;;;;;;;;;;;;;;AAcG;AACU,IAAA,QAAA,CAAA,IAAI,GAAG,CAAK,KAAQ,MAAe;AAC9C,QAAA,IAAI,EAAE,cAAc;QACpB,KAAK;AACN,KAAA,CAAC;AAEF;;;;;;;;;;AAUG;AACU,IAAA,QAAA,CAAA,IAAI,GAAS,EAAE,IAAI,EAAE,cAAc,EAAW;AAE3D;;;;;;AAMG;IACU,QAAA,CAAA,MAAM,GAAG,CACpB,QAAW,KACqB,QAAQ,CAAC,IAAI,KAAK,cAAc;AAElE;;;;;;AAMG;IACU,QAAA,CAAA,MAAM,GAAG,CACpB,QAAW,KACqB,QAAQ,CAAC,IAAI,KAAK,cAAc;AAElE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCG;AACU,IAAA,QAAA,CAAA,WAAW,GAAG,CAAiB,QAAW,KAAe;AACpE,QAAA,IAAI,SAA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