@nlozgachev/pipelined 0.12.0 → 0.13.0
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/LICENCE +28 -0
- package/README.md +1 -1
- package/{types/src/Types/NonEmptyList.d.ts → dist/NonEmptyList-BlGFjor5.d.mts} +4 -3
- package/dist/NonEmptyList-BlGFjor5.d.ts +30 -0
- package/dist/Task-BB8Wmc1J.d.ts +677 -0
- package/dist/Task-ChKyH0pF.d.mts +677 -0
- package/dist/chunk-DBIC62UV.mjs +6 -0
- package/dist/chunk-QPTGO5AS.mjs +150 -0
- package/dist/composition.d.mts +495 -0
- package/dist/composition.d.ts +495 -0
- package/dist/composition.js +188 -0
- package/dist/composition.mjs +135 -0
- package/dist/core.d.mts +2170 -0
- package/dist/core.d.ts +2170 -0
- package/dist/core.js +698 -0
- package/dist/core.mjs +517 -0
- package/dist/types.d.mts +54 -0
- package/{types/src/Types/Brand.d.ts → dist/types.d.ts} +6 -4
- package/dist/types.js +41 -0
- package/dist/types.mjs +14 -0
- package/dist/utils.d.mts +1285 -0
- package/dist/utils.d.ts +1285 -0
- package/dist/utils.js +722 -0
- package/dist/utils.mjs +553 -0
- package/package.json +63 -69
- package/esm/mod.js +0 -3
- package/esm/package.json +0 -3
- package/esm/src/Composition/compose.js +0 -3
- package/esm/src/Composition/converge.js +0 -3
- package/esm/src/Composition/curry.js +0 -42
- package/esm/src/Composition/flip.js +0 -20
- package/esm/src/Composition/flow.js +0 -8
- package/esm/src/Composition/fn.js +0 -85
- package/esm/src/Composition/index.js +0 -13
- package/esm/src/Composition/juxt.js +0 -3
- package/esm/src/Composition/memoize.js +0 -66
- package/esm/src/Composition/not.js +0 -25
- package/esm/src/Composition/on.js +0 -12
- package/esm/src/Composition/pipe.js +0 -3
- package/esm/src/Composition/tap.js +0 -33
- package/esm/src/Composition/uncurry.js +0 -32
- package/esm/src/Core/Deferred.js +0 -30
- package/esm/src/Core/InternalTypes.js +0 -1
- package/esm/src/Core/Lens.js +0 -98
- package/esm/src/Core/Logged.js +0 -111
- package/esm/src/Core/Option.js +0 -191
- package/esm/src/Core/Optional.js +0 -160
- package/esm/src/Core/Predicate.js +0 -133
- package/esm/src/Core/Reader.js +0 -134
- package/esm/src/Core/Refinement.js +0 -115
- package/esm/src/Core/RemoteData.js +0 -211
- package/esm/src/Core/Result.js +0 -170
- package/esm/src/Core/State.js +0 -181
- package/esm/src/Core/Task.js +0 -223
- package/esm/src/Core/TaskOption.js +0 -106
- package/esm/src/Core/TaskResult.js +0 -127
- package/esm/src/Core/TaskValidation.js +0 -128
- package/esm/src/Core/These.js +0 -245
- package/esm/src/Core/Tuple.js +0 -112
- package/esm/src/Core/Validation.js +0 -212
- package/esm/src/Core/index.js +0 -18
- package/esm/src/Types/Brand.js +0 -28
- package/esm/src/Types/NonEmptyList.js +0 -14
- package/esm/src/Types/index.js +0 -2
- package/esm/src/Utils/Arr.js +0 -570
- package/esm/src/Utils/Dict.js +0 -421
- package/esm/src/Utils/Num.js +0 -124
- package/esm/src/Utils/Rec.js +0 -241
- package/esm/src/Utils/Str.js +0 -134
- package/esm/src/Utils/Uniq.js +0 -265
- package/esm/src/Utils/index.js +0 -6
- package/script/mod.js +0 -19
- package/script/package.json +0 -3
- package/script/src/Composition/compose.js +0 -6
- package/script/src/Composition/converge.js +0 -6
- package/script/src/Composition/curry.js +0 -48
- package/script/src/Composition/flip.js +0 -24
- package/script/src/Composition/flow.js +0 -11
- package/script/src/Composition/fn.js +0 -98
- package/script/src/Composition/index.js +0 -29
- package/script/src/Composition/juxt.js +0 -6
- package/script/src/Composition/memoize.js +0 -71
- package/script/src/Composition/not.js +0 -29
- package/script/src/Composition/on.js +0 -16
- package/script/src/Composition/pipe.js +0 -6
- package/script/src/Composition/tap.js +0 -37
- package/script/src/Composition/uncurry.js +0 -38
- package/script/src/Core/Deferred.js +0 -33
- package/script/src/Core/InternalTypes.js +0 -2
- package/script/src/Core/Lens.js +0 -101
- package/script/src/Core/Logged.js +0 -114
- package/script/src/Core/Option.js +0 -194
- package/script/src/Core/Optional.js +0 -163
- package/script/src/Core/Predicate.js +0 -136
- package/script/src/Core/Reader.js +0 -137
- package/script/src/Core/Refinement.js +0 -118
- package/script/src/Core/RemoteData.js +0 -214
- package/script/src/Core/Result.js +0 -173
- package/script/src/Core/State.js +0 -184
- package/script/src/Core/Task.js +0 -226
- package/script/src/Core/TaskOption.js +0 -109
- package/script/src/Core/TaskResult.js +0 -130
- package/script/src/Core/TaskValidation.js +0 -131
- package/script/src/Core/These.js +0 -248
- package/script/src/Core/Tuple.js +0 -115
- package/script/src/Core/Validation.js +0 -215
- package/script/src/Core/index.js +0 -34
- package/script/src/Types/Brand.js +0 -31
- package/script/src/Types/NonEmptyList.js +0 -18
- package/script/src/Types/index.js +0 -18
- package/script/src/Utils/Arr.js +0 -573
- package/script/src/Utils/Dict.js +0 -424
- package/script/src/Utils/Num.js +0 -127
- package/script/src/Utils/Rec.js +0 -244
- package/script/src/Utils/Str.js +0 -137
- package/script/src/Utils/Uniq.js +0 -268
- package/script/src/Utils/index.js +0 -22
- package/types/mod.d.ts +0 -4
- package/types/mod.d.ts.map +0 -1
- package/types/src/Composition/compose.d.ts +0 -33
- package/types/src/Composition/compose.d.ts.map +0 -1
- package/types/src/Composition/converge.d.ts +0 -21
- package/types/src/Composition/converge.d.ts.map +0 -1
- package/types/src/Composition/curry.d.ts +0 -43
- package/types/src/Composition/curry.d.ts.map +0 -1
- package/types/src/Composition/flip.d.ts +0 -21
- package/types/src/Composition/flip.d.ts.map +0 -1
- package/types/src/Composition/flow.d.ts +0 -56
- package/types/src/Composition/flow.d.ts.map +0 -1
- package/types/src/Composition/fn.d.ts +0 -76
- package/types/src/Composition/fn.d.ts.map +0 -1
- package/types/src/Composition/index.d.ts +0 -14
- package/types/src/Composition/index.d.ts.map +0 -1
- package/types/src/Composition/juxt.d.ts +0 -18
- package/types/src/Composition/juxt.d.ts.map +0 -1
- package/types/src/Composition/memoize.d.ts +0 -46
- package/types/src/Composition/memoize.d.ts.map +0 -1
- package/types/src/Composition/not.d.ts +0 -26
- package/types/src/Composition/not.d.ts.map +0 -1
- package/types/src/Composition/on.d.ts +0 -13
- package/types/src/Composition/on.d.ts.map +0 -1
- package/types/src/Composition/pipe.d.ts +0 -56
- package/types/src/Composition/pipe.d.ts.map +0 -1
- package/types/src/Composition/tap.d.ts +0 -31
- package/types/src/Composition/tap.d.ts.map +0 -1
- package/types/src/Composition/uncurry.d.ts +0 -54
- package/types/src/Composition/uncurry.d.ts.map +0 -1
- package/types/src/Core/Deferred.d.ts +0 -49
- package/types/src/Core/Deferred.d.ts.map +0 -1
- package/types/src/Core/InternalTypes.d.ts +0 -23
- package/types/src/Core/InternalTypes.d.ts.map +0 -1
- package/types/src/Core/Lens.d.ts +0 -118
- package/types/src/Core/Lens.d.ts.map +0 -1
- package/types/src/Core/Logged.d.ts +0 -126
- package/types/src/Core/Logged.d.ts.map +0 -1
- package/types/src/Core/Option.d.ts +0 -209
- package/types/src/Core/Option.d.ts.map +0 -1
- package/types/src/Core/Optional.d.ts +0 -158
- package/types/src/Core/Optional.d.ts.map +0 -1
- package/types/src/Core/Predicate.d.ts +0 -161
- package/types/src/Core/Predicate.d.ts.map +0 -1
- package/types/src/Core/Reader.d.ts +0 -156
- package/types/src/Core/Reader.d.ts.map +0 -1
- package/types/src/Core/Refinement.d.ts +0 -138
- package/types/src/Core/Refinement.d.ts.map +0 -1
- package/types/src/Core/RemoteData.d.ts +0 -197
- package/types/src/Core/RemoteData.d.ts.map +0 -1
- package/types/src/Core/Result.d.ts +0 -182
- package/types/src/Core/Result.d.ts.map +0 -1
- package/types/src/Core/State.d.ts +0 -192
- package/types/src/Core/State.d.ts.map +0 -1
- package/types/src/Core/Task.d.ts +0 -219
- package/types/src/Core/Task.d.ts.map +0 -1
- package/types/src/Core/TaskOption.d.ts +0 -121
- package/types/src/Core/TaskOption.d.ts.map +0 -1
- package/types/src/Core/TaskResult.d.ts +0 -119
- package/types/src/Core/TaskResult.d.ts.map +0 -1
- package/types/src/Core/TaskValidation.d.ts +0 -144
- package/types/src/Core/TaskValidation.d.ts.map +0 -1
- package/types/src/Core/These.d.ts +0 -225
- package/types/src/Core/These.d.ts.map +0 -1
- package/types/src/Core/Tuple.d.ts +0 -129
- package/types/src/Core/Tuple.d.ts.map +0 -1
- package/types/src/Core/Validation.d.ts +0 -203
- package/types/src/Core/Validation.d.ts.map +0 -1
- package/types/src/Core/index.d.ts +0 -19
- package/types/src/Core/index.d.ts.map +0 -1
- package/types/src/Types/Brand.d.ts.map +0 -1
- package/types/src/Types/NonEmptyList.d.ts.map +0 -1
- package/types/src/Types/index.d.ts +0 -3
- package/types/src/Types/index.d.ts.map +0 -1
- package/types/src/Utils/Arr.d.ts +0 -403
- package/types/src/Utils/Arr.d.ts.map +0 -1
- package/types/src/Utils/Dict.d.ts +0 -310
- package/types/src/Utils/Dict.d.ts.map +0 -1
- package/types/src/Utils/Num.d.ts +0 -110
- package/types/src/Utils/Num.d.ts.map +0 -1
- package/types/src/Utils/Rec.d.ts +0 -159
- package/types/src/Utils/Rec.d.ts.map +0 -1
- package/types/src/Utils/Str.d.ts +0 -128
- package/types/src/Utils/Str.d.ts.map +0 -1
- package/types/src/Utils/Uniq.d.ts +0 -179
- package/types/src/Utils/Uniq.d.ts.map +0 -1
- package/types/src/Utils/index.d.ts +0 -7
- package/types/src/Utils/index.d.ts.map +0 -1
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
import { WithFirst, WithKind, WithSecond } from "./InternalTypes.js";
|
|
2
|
-
/**
|
|
3
|
-
* These<A, B> is an inclusive-OR type: it holds a first value (A), a second
|
|
4
|
-
* value (B), or both simultaneously. Neither side carries a success/failure
|
|
5
|
-
* connotation — it is a neutral pair where any combination is valid.
|
|
6
|
-
*
|
|
7
|
-
* - First(a) — only a first value
|
|
8
|
-
* - Second(b) — only a second value
|
|
9
|
-
* - Both(a, b) — first and second values simultaneously
|
|
10
|
-
*
|
|
11
|
-
* A common use: lenient parsers or processors that carry a diagnostic note
|
|
12
|
-
* alongside a result, without losing either piece of information.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* const parse = (s: string): These<number, string> => {
|
|
17
|
-
* const trimmed = s.trim();
|
|
18
|
-
* const n = parseFloat(trimmed);
|
|
19
|
-
* if (isNaN(n)) return These.second("Not a number");
|
|
20
|
-
* if (s !== trimmed) return These.both(n, "Leading/trailing whitespace trimmed");
|
|
21
|
-
* return These.first(n);
|
|
22
|
-
* };
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
export type These<A, B> = TheseFirst<A> | TheseSecond<B> | TheseBoth<A, B>;
|
|
26
|
-
export type TheseFirst<T> = WithKind<"First"> & WithFirst<T>;
|
|
27
|
-
export type TheseSecond<T> = WithKind<"Second"> & WithSecond<T>;
|
|
28
|
-
export type TheseBoth<First, Second> = WithKind<"Both"> & WithFirst<First> & WithSecond<Second>;
|
|
29
|
-
export declare namespace These {
|
|
30
|
-
/**
|
|
31
|
-
* Creates a These holding only a first value.
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```ts
|
|
35
|
-
* These.first(42); // { kind: "First", first: 42 }
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
const first: <A>(value: A) => TheseFirst<A>;
|
|
39
|
-
/**
|
|
40
|
-
* Creates a These holding only a second value.
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```ts
|
|
44
|
-
* These.second("warning"); // { kind: "Second", second: "warning" }
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
const second: <B>(value: B) => TheseSecond<B>;
|
|
48
|
-
/**
|
|
49
|
-
* Creates a These holding both a first and a second value simultaneously.
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```ts
|
|
53
|
-
* These.both(42, "Deprecated API used"); // { kind: "Both", first: 42, second: "Deprecated API used" }
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
const both: <A, B>(first: A, second: B) => TheseBoth<A, B>;
|
|
57
|
-
/**
|
|
58
|
-
* Type guard — checks if a These holds only a first value.
|
|
59
|
-
*/
|
|
60
|
-
const isFirst: <A, B>(data: These<A, B>) => data is TheseFirst<A>;
|
|
61
|
-
/**
|
|
62
|
-
* Type guard — checks if a These holds only a second value.
|
|
63
|
-
*/
|
|
64
|
-
const isSecond: <A, B>(data: These<A, B>) => data is TheseSecond<B>;
|
|
65
|
-
/**
|
|
66
|
-
* Type guard — checks if a These holds both values simultaneously.
|
|
67
|
-
*/
|
|
68
|
-
const isBoth: <A, B>(data: These<A, B>) => data is TheseBoth<A, B>;
|
|
69
|
-
/**
|
|
70
|
-
* Returns true if the These contains a first value (First or Both).
|
|
71
|
-
*/
|
|
72
|
-
const hasFirst: <A, B>(data: These<A, B>) => data is TheseFirst<A> | TheseBoth<A, B>;
|
|
73
|
-
/**
|
|
74
|
-
* Returns true if the These contains a second value (Second or Both).
|
|
75
|
-
*/
|
|
76
|
-
const hasSecond: <A, B>(data: These<A, B>) => data is TheseSecond<B> | TheseBoth<A, B>;
|
|
77
|
-
/**
|
|
78
|
-
* Transforms the first value, leaving the second unchanged.
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* ```ts
|
|
82
|
-
* pipe(These.first(5), These.mapFirst(n => n * 2)); // First(10)
|
|
83
|
-
* pipe(These.both(5, "warn"), These.mapFirst(n => n * 2)); // Both(10, "warn")
|
|
84
|
-
* pipe(These.second("warn"), These.mapFirst(n => n * 2)); // Second("warn")
|
|
85
|
-
* ```
|
|
86
|
-
*/
|
|
87
|
-
const mapFirst: <A, C>(f: (a: A) => C) => <B>(data: These<A, B>) => These<C, B>;
|
|
88
|
-
/**
|
|
89
|
-
* Transforms the second value, leaving the first unchanged.
|
|
90
|
-
*
|
|
91
|
-
* @example
|
|
92
|
-
* ```ts
|
|
93
|
-
* pipe(These.second("warn"), These.mapSecond(e => e.toUpperCase())); // Second("WARN")
|
|
94
|
-
* pipe(These.both(5, "warn"), These.mapSecond(e => e.toUpperCase())); // Both(5, "WARN")
|
|
95
|
-
* ```
|
|
96
|
-
*/
|
|
97
|
-
const mapSecond: <B, D>(f: (b: B) => D) => <A>(data: These<A, B>) => These<A, D>;
|
|
98
|
-
/**
|
|
99
|
-
* Transforms both the first and second values independently.
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* ```ts
|
|
103
|
-
* pipe(
|
|
104
|
-
* These.both(5, "warn"),
|
|
105
|
-
* These.mapBoth(n => n * 2, e => e.toUpperCase())
|
|
106
|
-
* ); // Both(10, "WARN")
|
|
107
|
-
* ```
|
|
108
|
-
*/
|
|
109
|
-
const mapBoth: <A, C, B, D>(onFirst: (a: A) => C, onSecond: (b: B) => D) => (data: These<A, B>) => These<C, D>;
|
|
110
|
-
/**
|
|
111
|
-
* Chains These computations by passing the first value to f.
|
|
112
|
-
* Second propagates unchanged; First and Both apply f to the first value.
|
|
113
|
-
*
|
|
114
|
-
* @example
|
|
115
|
-
* ```ts
|
|
116
|
-
* const double = (n: number): These<number, string> => These.first(n * 2);
|
|
117
|
-
*
|
|
118
|
-
* pipe(These.first(5), These.chainFirst(double)); // First(10)
|
|
119
|
-
* pipe(These.both(5, "warn"), These.chainFirst(double)); // First(10)
|
|
120
|
-
* pipe(These.second("warn"), These.chainFirst(double)); // Second("warn")
|
|
121
|
-
* ```
|
|
122
|
-
*/
|
|
123
|
-
const chainFirst: <A, B, C>(f: (a: A) => These<C, B>) => (data: These<A, B>) => These<C, B>;
|
|
124
|
-
/**
|
|
125
|
-
* Chains These computations by passing the second value to f.
|
|
126
|
-
* First propagates unchanged; Second and Both apply f to the second value.
|
|
127
|
-
*
|
|
128
|
-
* @example
|
|
129
|
-
* ```ts
|
|
130
|
-
* const shout = (s: string): These<number, string> => These.second(s.toUpperCase());
|
|
131
|
-
*
|
|
132
|
-
* pipe(These.second("warn"), These.chainSecond(shout)); // Second("WARN")
|
|
133
|
-
* pipe(These.both(5, "warn"), These.chainSecond(shout)); // Second("WARN")
|
|
134
|
-
* pipe(These.first(5), These.chainSecond(shout)); // First(5)
|
|
135
|
-
* ```
|
|
136
|
-
*/
|
|
137
|
-
const chainSecond: <A, B, D>(f: (b: B) => These<A, D>) => (data: These<A, B>) => These<A, D>;
|
|
138
|
-
/**
|
|
139
|
-
* Extracts a value from a These by providing handlers for all three cases.
|
|
140
|
-
*
|
|
141
|
-
* @example
|
|
142
|
-
* ```ts
|
|
143
|
-
* pipe(
|
|
144
|
-
* these,
|
|
145
|
-
* These.fold(
|
|
146
|
-
* a => `First: ${a}`,
|
|
147
|
-
* b => `Second: ${b}`,
|
|
148
|
-
* (a, b) => `Both: ${a} / ${b}`
|
|
149
|
-
* )
|
|
150
|
-
* );
|
|
151
|
-
* ```
|
|
152
|
-
*/
|
|
153
|
-
const fold: <A, B, C>(onFirst: (a: A) => C, onSecond: (b: B) => C, onBoth: (a: A, b: B) => C) => (data: These<A, B>) => C;
|
|
154
|
-
/**
|
|
155
|
-
* Pattern matches on a These, returning the result of the matching case.
|
|
156
|
-
*
|
|
157
|
-
* @example
|
|
158
|
-
* ```ts
|
|
159
|
-
* pipe(
|
|
160
|
-
* these,
|
|
161
|
-
* These.match({
|
|
162
|
-
* first: a => `First: ${a}`,
|
|
163
|
-
* second: b => `Second: ${b}`,
|
|
164
|
-
* both: (a, b) => `Both: ${a} / ${b}`
|
|
165
|
-
* })
|
|
166
|
-
* );
|
|
167
|
-
* ```
|
|
168
|
-
*/
|
|
169
|
-
const match: <A, B, C>(cases: {
|
|
170
|
-
first: (a: A) => C;
|
|
171
|
-
second: (b: B) => C;
|
|
172
|
-
both: (a: A, b: B) => C;
|
|
173
|
-
}) => (data: These<A, B>) => C;
|
|
174
|
-
/**
|
|
175
|
-
* Returns the first value, or a default if the These has no first value.
|
|
176
|
-
* The default can be a different type, widening the result to `A | C`.
|
|
177
|
-
*
|
|
178
|
-
* @example
|
|
179
|
-
* ```ts
|
|
180
|
-
* pipe(These.first(5), These.getFirstOrElse(() => 0)); // 5
|
|
181
|
-
* pipe(These.both(5, "warn"), These.getFirstOrElse(() => 0)); // 5
|
|
182
|
-
* pipe(These.second("warn"), These.getFirstOrElse(() => 0)); // 0
|
|
183
|
-
* pipe(These.second("warn"), These.getFirstOrElse(() => null)); // null — typed as number | null
|
|
184
|
-
* ```
|
|
185
|
-
*/
|
|
186
|
-
const getFirstOrElse: <A, C>(defaultValue: () => C) => <B>(data: These<A, B>) => A | C;
|
|
187
|
-
/**
|
|
188
|
-
* Returns the second value, or a default if the These has no second value.
|
|
189
|
-
* The default can be a different type, widening the result to `B | D`.
|
|
190
|
-
*
|
|
191
|
-
* @example
|
|
192
|
-
* ```ts
|
|
193
|
-
* pipe(These.second("warn"), These.getSecondOrElse(() => "none")); // "warn"
|
|
194
|
-
* pipe(These.both(5, "warn"), These.getSecondOrElse(() => "none")); // "warn"
|
|
195
|
-
* pipe(These.first(5), These.getSecondOrElse(() => "none")); // "none"
|
|
196
|
-
* pipe(These.first(5), These.getSecondOrElse(() => null)); // null — typed as string | null
|
|
197
|
-
* ```
|
|
198
|
-
*/
|
|
199
|
-
const getSecondOrElse: <B, D>(defaultValue: () => D) => <A>(data: These<A, B>) => B | D;
|
|
200
|
-
/**
|
|
201
|
-
* Executes a side effect on the first value without changing the These.
|
|
202
|
-
* Useful for logging or debugging.
|
|
203
|
-
*
|
|
204
|
-
* @example
|
|
205
|
-
* ```ts
|
|
206
|
-
* pipe(These.first(5), These.tap(console.log)); // logs 5, returns First(5)
|
|
207
|
-
* ```
|
|
208
|
-
*/
|
|
209
|
-
const tap: <A>(f: (a: A) => void) => <B>(data: These<A, B>) => These<A, B>;
|
|
210
|
-
/**
|
|
211
|
-
* Swaps the roles of first and second values.
|
|
212
|
-
* - First(a) → Second(a)
|
|
213
|
-
* - Second(b) → First(b)
|
|
214
|
-
* - Both(a, b) → Both(b, a)
|
|
215
|
-
*
|
|
216
|
-
* @example
|
|
217
|
-
* ```ts
|
|
218
|
-
* These.swap(These.first(5)); // Second(5)
|
|
219
|
-
* These.swap(These.second("warn")); // First("warn")
|
|
220
|
-
* These.swap(These.both(5, "warn")); // Both("warn", 5)
|
|
221
|
-
* ```
|
|
222
|
-
*/
|
|
223
|
-
const swap: <A, B>(data: These<A, B>) => These<B, A>;
|
|
224
|
-
}
|
|
225
|
-
//# sourceMappingURL=These.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"These.d.ts","sourceRoot":"","sources":["../../../src/src/Core/These.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAE3E,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,QAAQ,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;AAC7D,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;AAChE,MAAM,MAAM,SAAS,CAAC,KAAK,EAAE,MAAM,IAAI,QAAQ,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;AAEhG,yBAAiB,KAAK,CAAC;IACtB;;;;;;;OAOG;IACI,MAAM,KAAK,GAAI,CAAC,EAAE,OAAO,CAAC,KAAG,UAAU,CAAC,CAAC,CAAsC,CAAC;IAEvF;;;;;;;OAOG;IACI,MAAM,MAAM,GAAI,CAAC,EAAE,OAAO,CAAC,KAAG,WAAW,CAAC,CAAC,CAAwC,CAAC;IAE3F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|
-
/**
|
|
2
|
-
* Tuple<A, B> represents a pair of two values that are always both present.
|
|
3
|
-
* It is a typed alias for `readonly [A, B]`.
|
|
4
|
-
*
|
|
5
|
-
* Use Tuple when two values always travel together through a pipeline and you
|
|
6
|
-
* want to transform either or both sides without destructuring.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* import { Tuple } from "@nlozgachev/pipelined/core";
|
|
11
|
-
* import { pipe } from "@nlozgachev/pipelined/composition";
|
|
12
|
-
*
|
|
13
|
-
* const entry = Tuple.make("alice", 42);
|
|
14
|
-
*
|
|
15
|
-
* pipe(
|
|
16
|
-
* entry,
|
|
17
|
-
* Tuple.mapFirst((name) => name.toUpperCase()),
|
|
18
|
-
* Tuple.mapSecond((score) => score * 2),
|
|
19
|
-
* Tuple.fold((name, score) => `${name}: ${score}`),
|
|
20
|
-
* ); // "ALICE: 84"
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export type Tuple<A, B> = readonly [A, B];
|
|
24
|
-
export declare namespace Tuple {
|
|
25
|
-
/**
|
|
26
|
-
* Creates a pair from two values.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```ts
|
|
30
|
-
* Tuple.make("Paris", 2_161_000); // ["Paris", 2161000]
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
const make: <A, B>(first: A, second: B) => Tuple<A, B>;
|
|
34
|
-
/**
|
|
35
|
-
* Returns the first value from the pair.
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```ts
|
|
39
|
-
* Tuple.first(Tuple.make("Paris", 2_161_000)); // "Paris"
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
const first: <A, B>(tuple: Tuple<A, B>) => A;
|
|
43
|
-
/**
|
|
44
|
-
* Returns the second value from the pair.
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```ts
|
|
48
|
-
* Tuple.second(Tuple.make("Paris", 2_161_000)); // 2161000
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
const second: <A, B>(tuple: Tuple<A, B>) => B;
|
|
52
|
-
/**
|
|
53
|
-
* Transforms the first value, leaving the second unchanged.
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```ts
|
|
57
|
-
* pipe(Tuple.make("alice", 42), Tuple.mapFirst((s) => s.toUpperCase())); // ["ALICE", 42]
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
const mapFirst: <A, C>(f: (a: A) => C) => <B>(tuple: Tuple<A, B>) => Tuple<C, B>;
|
|
61
|
-
/**
|
|
62
|
-
* Transforms the second value, leaving the first unchanged.
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```ts
|
|
66
|
-
* pipe(Tuple.make("alice", 42), Tuple.mapSecond((n) => n * 2)); // ["alice", 84]
|
|
67
|
-
* ```
|
|
68
|
-
*/
|
|
69
|
-
const mapSecond: <B, D>(f: (b: B) => D) => <A>(tuple: Tuple<A, B>) => Tuple<A, D>;
|
|
70
|
-
/**
|
|
71
|
-
* Transforms both values independently in a single step.
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* ```ts
|
|
75
|
-
* pipe(
|
|
76
|
-
* Tuple.make("alice", 42),
|
|
77
|
-
* Tuple.mapBoth(
|
|
78
|
-
* (name) => name.toUpperCase(),
|
|
79
|
-
* (score) => score * 2,
|
|
80
|
-
* ),
|
|
81
|
-
* ); // ["ALICE", 84]
|
|
82
|
-
* ```
|
|
83
|
-
*/
|
|
84
|
-
const mapBoth: <A, C, B, D>(onFirst: (a: A) => C, onSecond: (b: B) => D) => (tuple: Tuple<A, B>) => Tuple<C, D>;
|
|
85
|
-
/**
|
|
86
|
-
* Applies a binary function to both values, collapsing the pair into a single value.
|
|
87
|
-
* Useful as the final step when consuming a pair in a pipeline.
|
|
88
|
-
*
|
|
89
|
-
* @example
|
|
90
|
-
* ```ts
|
|
91
|
-
* pipe(Tuple.make("Alice", 100), Tuple.fold((name, score) => `${name}: ${score}`));
|
|
92
|
-
* // "Alice: 100"
|
|
93
|
-
* ```
|
|
94
|
-
*/
|
|
95
|
-
const fold: <A, B, C>(f: (a: A, b: B) => C) => (tuple: Tuple<A, B>) => C;
|
|
96
|
-
/**
|
|
97
|
-
* Swaps the two values: `[A, B]` becomes `[B, A]`.
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* ```ts
|
|
101
|
-
* Tuple.swap(Tuple.make("key", 1)); // [1, "key"]
|
|
102
|
-
* ```
|
|
103
|
-
*/
|
|
104
|
-
const swap: <A, B>(tuple: Tuple<A, B>) => Tuple<B, A>;
|
|
105
|
-
/**
|
|
106
|
-
* Converts the pair to a heterogeneous readonly array `readonly (A | B)[]`.
|
|
107
|
-
*
|
|
108
|
-
* @example
|
|
109
|
-
* ```ts
|
|
110
|
-
* Tuple.toArray(Tuple.make("hello", 42)); // ["hello", 42]
|
|
111
|
-
* ```
|
|
112
|
-
*/
|
|
113
|
-
const toArray: <A, B>(tuple: Tuple<A, B>) => readonly (A | B)[];
|
|
114
|
-
/**
|
|
115
|
-
* Runs a side effect with both values without changing the pair.
|
|
116
|
-
* Useful for logging or debugging in the middle of a pipeline.
|
|
117
|
-
*
|
|
118
|
-
* @example
|
|
119
|
-
* ```ts
|
|
120
|
-
* pipe(
|
|
121
|
-
* Tuple.make("Paris", 2_161_000),
|
|
122
|
-
* Tuple.tap((city, pop) => console.log(`${city}: ${pop}`)),
|
|
123
|
-
* Tuple.mapSecond((n) => n / 1_000_000),
|
|
124
|
-
* ); // logs "Paris: 2161000", returns ["Paris", 2.161]
|
|
125
|
-
* ```
|
|
126
|
-
*/
|
|
127
|
-
const tap: <A, B>(f: (a: A, b: B) => void) => (tuple: Tuple<A, B>) => Tuple<A, B>;
|
|
128
|
-
}
|
|
129
|
-
//# sourceMappingURL=Tuple.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3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C,EAAE,CAAC,KAAK,CAAC,MAAM,OAAO,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,KAAK,CAAC,CAAC,EAAE,CAAC,CAG5F,CAAC;IAEH;;;;;;;;;OASG;IACI,MAAM,IAAI,GAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,OAAO,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,CAA0B,CAAC;IAExG;;;;;;;OAOG;IACI,MAAM,IAAI,GAAI,CAAC,EAAE,CAAC,EAAE,OAAO,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,KAAK,CAAC,CAAC,EAAE,CAAC,CAAyB,CAAC;IAEpF;;;;;;;OAOG;IACI,MAAM,OAAO,GAAI,CAAC,EAAE,CAAC,EAAE,OAAO,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,EAAgB,CAAC;IAEpF;;;;;;;;;;;;OAYG;IACI,MAAM,GAAG,GAAI,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,IAAI,MAAM,OAAO,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,KAAK,CAAC,CAAC,EAAE,CAAC,CAGrF,CAAC;CACF"}
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
import { NonEmptyList } from "../Types/NonEmptyList.js";
|
|
2
|
-
import { WithErrors, WithKind, WithValue } from "./InternalTypes.js";
|
|
3
|
-
/**
|
|
4
|
-
* Validation represents a value that is either valid with a success value,
|
|
5
|
-
* or invalid with accumulated errors.
|
|
6
|
-
* Unlike Result, Validation can accumulate multiple errors instead of short-circuiting.
|
|
7
|
-
*
|
|
8
|
-
* Use Validation when you need to collect all errors (e.g., form validation).
|
|
9
|
-
* Use Result when you want to fail fast on the first error.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* const validateName = (name: string): Validation<string, string> =>
|
|
14
|
-
* name.length > 0 ? Validation.valid(name) : Validation.invalid("Name is required");
|
|
15
|
-
*
|
|
16
|
-
* const validateAge = (age: number): Validation<string, number> =>
|
|
17
|
-
* age >= 0 ? Validation.valid(age) : Validation.invalid("Age must be positive");
|
|
18
|
-
*
|
|
19
|
-
* // Accumulates all errors using ap
|
|
20
|
-
* pipe(
|
|
21
|
-
* Validation.valid((name: string) => (age: number) => ({ name, age })),
|
|
22
|
-
* Validation.ap(validateName("")),
|
|
23
|
-
* Validation.ap(validateAge(-1))
|
|
24
|
-
* );
|
|
25
|
-
* // Invalid(["Name is required", "Age must be positive"])
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export type Validation<E, A> = Valid<A> | Invalid<E>;
|
|
29
|
-
export type Valid<A> = WithKind<"Valid"> & WithValue<A>;
|
|
30
|
-
export type Invalid<E> = WithKind<"Invalid"> & WithErrors<E>;
|
|
31
|
-
export declare namespace Validation {
|
|
32
|
-
/**
|
|
33
|
-
* Wraps a value in a valid Validation.
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```ts
|
|
37
|
-
* Validation.valid(42); // Valid(42)
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
const valid: <E, A>(value: A) => Validation<E, A>;
|
|
41
|
-
/**
|
|
42
|
-
* Creates an invalid Validation from a single error.
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* ```ts
|
|
46
|
-
* Validation.invalid("Invalid input");
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
const invalid: <E>(error: E) => Invalid<E>;
|
|
50
|
-
/**
|
|
51
|
-
* Creates an invalid Validation from multiple errors.
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```ts
|
|
55
|
-
* Validation.invalidAll(["Invalid input"]);
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
const invalidAll: <E>(errors: NonEmptyList<E>) => Invalid<E>;
|
|
59
|
-
/**
|
|
60
|
-
* Type guard that checks if a Validation is valid.
|
|
61
|
-
*/
|
|
62
|
-
const isValid: <E, A>(data: Validation<E, A>) => data is Valid<A>;
|
|
63
|
-
/**
|
|
64
|
-
* Type guard that checks if a Validation is invalid.
|
|
65
|
-
*/
|
|
66
|
-
const isInvalid: <E, A>(data: Validation<E, A>) => data is Invalid<E>;
|
|
67
|
-
/**
|
|
68
|
-
* Transforms the success value inside a Validation.
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```ts
|
|
72
|
-
* pipe(Validation.valid(5), Validation.map(n => n * 2)); // Valid(10)
|
|
73
|
-
* pipe(Validation.invalid("oops"), Validation.map(n => n * 2)); // Invalid(["oops"])
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
|
-
const map: <A, B>(f: (a: A) => B) => <E>(data: Validation<E, A>) => Validation<E, B>;
|
|
77
|
-
/**
|
|
78
|
-
* Applies a function wrapped in a Validation to a value wrapped in a Validation.
|
|
79
|
-
* Accumulates errors from both sides.
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* ```ts
|
|
83
|
-
* const add = (a: number) => (b: number) => a + b;
|
|
84
|
-
* pipe(
|
|
85
|
-
* Validation.valid(add),
|
|
86
|
-
* Validation.ap(Validation.valid(5)),
|
|
87
|
-
* Validation.ap(Validation.valid(3))
|
|
88
|
-
* ); // Valid(8)
|
|
89
|
-
*
|
|
90
|
-
* pipe(
|
|
91
|
-
* Validation.valid(add),
|
|
92
|
-
* Validation.ap(Validation.invalid<string, number>("bad a")),
|
|
93
|
-
* Validation.ap(Validation.invalid<string, number>("bad b"))
|
|
94
|
-
* ); // Invalid(["bad a", "bad b"])
|
|
95
|
-
* ```
|
|
96
|
-
*/
|
|
97
|
-
const ap: <E, A>(arg: Validation<E, A>) => <B>(data: Validation<E, (a: A) => B>) => Validation<E, B>;
|
|
98
|
-
/**
|
|
99
|
-
* Extracts the value from a Validation by providing handlers for both cases.
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* ```ts
|
|
103
|
-
* pipe(
|
|
104
|
-
* Validation.valid(42),
|
|
105
|
-
* Validation.fold(
|
|
106
|
-
* errors => `Errors: ${errors.join(", ")}`,
|
|
107
|
-
* value => `Value: ${value}`
|
|
108
|
-
* )
|
|
109
|
-
* );
|
|
110
|
-
* ```
|
|
111
|
-
*/
|
|
112
|
-
const fold: <E, A, B>(onInvalid: (errors: NonEmptyList<E>) => B, onValid: (a: A) => B) => (data: Validation<E, A>) => B;
|
|
113
|
-
/**
|
|
114
|
-
* Pattern matches on a Validation, returning the result of the matching case.
|
|
115
|
-
*
|
|
116
|
-
* @example
|
|
117
|
-
* ```ts
|
|
118
|
-
* pipe(
|
|
119
|
-
* validation,
|
|
120
|
-
* Validation.match({
|
|
121
|
-
* valid: value => `Got ${value}`,
|
|
122
|
-
* invalid: errors => `Failed: ${errors.join(", ")}`
|
|
123
|
-
* })
|
|
124
|
-
* );
|
|
125
|
-
* ```
|
|
126
|
-
*/
|
|
127
|
-
const match: <E, A, B>(cases: {
|
|
128
|
-
valid: (a: A) => B;
|
|
129
|
-
invalid: (errors: NonEmptyList<E>) => B;
|
|
130
|
-
}) => (data: Validation<E, A>) => B;
|
|
131
|
-
/**
|
|
132
|
-
* Returns the success value or a default value if the Validation is invalid.
|
|
133
|
-
* The default can be a different type, widening the result to `A | B`.
|
|
134
|
-
*
|
|
135
|
-
* @example
|
|
136
|
-
* ```ts
|
|
137
|
-
* pipe(Validation.valid(5), Validation.getOrElse(() => 0)); // 5
|
|
138
|
-
* pipe(Validation.invalid("oops"), Validation.getOrElse(() => 0)); // 0
|
|
139
|
-
* pipe(Validation.invalid("oops"), Validation.getOrElse(() => null)); // null — typed as number | null
|
|
140
|
-
* ```
|
|
141
|
-
*/
|
|
142
|
-
const getOrElse: <E, A, B>(defaultValue: () => B) => (data: Validation<E, A>) => A | B;
|
|
143
|
-
/**
|
|
144
|
-
* Executes a side effect on the success value without changing the Validation.
|
|
145
|
-
*
|
|
146
|
-
* @example
|
|
147
|
-
* ```ts
|
|
148
|
-
* pipe(
|
|
149
|
-
* Validation.valid(5),
|
|
150
|
-
* Validation.tap(n => console.log("Value:", n)),
|
|
151
|
-
* Validation.map(n => n * 2)
|
|
152
|
-
* );
|
|
153
|
-
* ```
|
|
154
|
-
*/
|
|
155
|
-
const tap: <E, A>(f: (a: A) => void) => (data: Validation<E, A>) => Validation<E, A>;
|
|
156
|
-
/**
|
|
157
|
-
* Recovers from an Invalid state by providing a fallback Validation.
|
|
158
|
-
* The fallback receives the accumulated error list so callers can inspect which errors occurred.
|
|
159
|
-
* The fallback can produce a different success type, widening the result to `Validation<E, A | B>`.
|
|
160
|
-
*/
|
|
161
|
-
const recover: <E, A, B>(fallback: (errors: NonEmptyList<E>) => Validation<E, B>) => (data: Validation<E, A>) => Validation<E, A | B>;
|
|
162
|
-
/**
|
|
163
|
-
* Recovers from an Invalid state unless the errors contain any of the blocked errors.
|
|
164
|
-
* The fallback can produce a different success type, widening the result to `Validation<E, A | B>`.
|
|
165
|
-
*/
|
|
166
|
-
const recoverUnless: <E, A, B>(blockedErrors: readonly E[], fallback: () => Validation<E, B>) => (data: Validation<E, A>) => Validation<E, A | B>;
|
|
167
|
-
/**
|
|
168
|
-
* Combines two independent Validation instances into a tuple.
|
|
169
|
-
* If both are Valid, returns Valid with both values as a tuple.
|
|
170
|
-
* If either is Invalid, accumulates errors from both sides.
|
|
171
|
-
*
|
|
172
|
-
* @example
|
|
173
|
-
* ```ts
|
|
174
|
-
* Validation.product(
|
|
175
|
-
* Validation.valid("alice"),
|
|
176
|
-
* Validation.valid(30)
|
|
177
|
-
* ); // Valid(["alice", 30])
|
|
178
|
-
*
|
|
179
|
-
* Validation.product(
|
|
180
|
-
* Validation.invalid("Name required"),
|
|
181
|
-
* Validation.invalid("Age must be >= 0")
|
|
182
|
-
* ); // Invalid(["Name required", "Age must be >= 0"])
|
|
183
|
-
* ```
|
|
184
|
-
*/
|
|
185
|
-
const product: <E, A, B>(first: Validation<E, A>, second: Validation<E, B>) => Validation<E, readonly [A, B]>;
|
|
186
|
-
/**
|
|
187
|
-
* Combines a non-empty list of Validation instances, accumulating all errors.
|
|
188
|
-
* If all are Valid, returns Valid with all values collected into an array.
|
|
189
|
-
* If any are Invalid, returns Invalid with all accumulated errors.
|
|
190
|
-
*
|
|
191
|
-
* @example
|
|
192
|
-
* ```ts
|
|
193
|
-
* Validation.productAll([
|
|
194
|
-
* validateName(name),
|
|
195
|
-
* validateEmail(email),
|
|
196
|
-
* validateAge(age)
|
|
197
|
-
* ]);
|
|
198
|
-
* // Valid([name, email, age]) or Invalid([...all errors])
|
|
199
|
-
* ```
|
|
200
|
-
*/
|
|
201
|
-
const productAll: <E, A>(data: NonEmptyList<Validation<E, A>>) => Validation<E, readonly A[]>;
|
|
202
|
-
}
|
|
203
|
-
//# sourceMappingURL=Validation.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Validation.d.ts","sourceRoot":"","sources":["../../../src/src/Core/Validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAErD,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,QAAQ,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;AACxD,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,QAAQ,CAAC,SAAS,CAAC,GAAG,UAAU,C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B,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,eAAe,SAAS,CAAC,EAAE,EAAE,UAAU,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,MACtE,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,UAAU,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAIrC,CAAC;IAEV;;;;;;;;;;;;;;;;;OAiBG;IACI,MAAM,OAAO,GAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAC9B,OAAO,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,EACvB,QAAQ,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,KACtB,UAAU,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAO/B,CAAC;IAEF;;;;;;;;;;;;;;OAcG;IACI,MAAM,UAAU,GAAI,CAAC,EAAE,CAAC,EAC9B,MAAM,YAAY,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAClC,UAAU,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,CAQ5B,CAAC;CACF"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export * from "./Deferred.js";
|
|
2
|
-
export * from "./Lens.js";
|
|
3
|
-
export * from "./Logged.js";
|
|
4
|
-
export * from "./Option.js";
|
|
5
|
-
export * from "./Optional.js";
|
|
6
|
-
export * from "./Predicate.js";
|
|
7
|
-
export * from "./Reader.js";
|
|
8
|
-
export * from "./Refinement.js";
|
|
9
|
-
export * from "./RemoteData.js";
|
|
10
|
-
export * from "./Result.js";
|
|
11
|
-
export * from "./State.js";
|
|
12
|
-
export * from "./Task.js";
|
|
13
|
-
export * from "./TaskOption.js";
|
|
14
|
-
export * from "./TaskResult.js";
|
|
15
|
-
export * from "./TaskValidation.js";
|
|
16
|
-
export * from "./These.js";
|
|
17
|
-
export * from "./Tuple.js";
|
|
18
|
-
export * from "./Validation.js";
|
|
19
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/Core/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Brand.d.ts","sourceRoot":"","sources":["../../../src/src/Types/Brand.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,MAAM,EAAE,OAAO,MAAM,CAAC;AAEpC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,IAAI,CAAC,GAAG;IAAE,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;CAAE,CAAC;AAEtE,yBAAiB,KAAK,CAAC;IACtB;;;;;;;;;;;;OAYG;IACI,MAAM,IAAI,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,QAAQ,OAAO,CAAC,KAAG,KAAK,CAAC,CAAC,EAAE,CAAC,CAAyB,CAAC;IAE/F;;;;;;;;;OASG;IACI,MAAM,MAAM,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,SAAS,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,CAAiB,CAAC;CACrF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NonEmptyList.d.ts","sourceRoot":"","sources":["../../../src/src/Types/NonEmptyList.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;AAEnD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,EAC/B,MAAM,SAAS,CAAC,EAAE,KAChB,IAAI,IAAI,YAAY,CAAC,CAAC,CAAoB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/Types/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC"}
|