@nlozgachev/pipelined 0.11.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/Validation.js +0 -212
- package/esm/src/Core/index.js +0 -17
- 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/Num.js +0 -124
- package/esm/src/Utils/Rec.js +0 -215
- package/esm/src/Utils/Str.js +0 -134
- package/esm/src/Utils/index.js +0 -4
- 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/Validation.js +0 -215
- package/script/src/Core/index.js +0 -33
- 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/Num.js +0 -127
- package/script/src/Utils/Rec.js +0 -218
- package/script/src/Utils/Str.js +0 -137
- package/script/src/Utils/index.js +0 -20
- 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/Validation.d.ts +0 -203
- package/types/src/Core/Validation.d.ts.map +0 -1
- package/types/src/Core/index.d.ts +0 -18
- 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/Num.d.ts +0 -110
- package/types/src/Utils/Num.d.ts.map +0 -1
- package/types/src/Utils/Rec.d.ts +0 -143
- 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/index.d.ts +0 -5
- package/types/src/Utils/index.d.ts.map +0 -1
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { WithLog, WithValue } from "./InternalTypes.js";
|
|
2
|
-
/**
|
|
3
|
-
* A value paired with an accumulated log.
|
|
4
|
-
*
|
|
5
|
-
* `Logged<W, A>` pairs a result `A` with a sequence of log entries `W`. When
|
|
6
|
-
* you sequence two `Logged` computations with `chain`, the logs are
|
|
7
|
-
* automatically concatenated — you never have to thread the log array through
|
|
8
|
-
* your code manually.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```ts
|
|
12
|
-
* const program = pipe(
|
|
13
|
-
* Logged.make<string, number>(0),
|
|
14
|
-
* Logged.chain(n => pipe(
|
|
15
|
-
* Logged.tell("start"),
|
|
16
|
-
* Logged.map(() => n + 1),
|
|
17
|
-
* )),
|
|
18
|
-
* Logged.chain(n => pipe(
|
|
19
|
-
* Logged.tell("done"),
|
|
20
|
-
* Logged.map(() => n * 10),
|
|
21
|
-
* )),
|
|
22
|
-
* );
|
|
23
|
-
*
|
|
24
|
-
* Logged.run(program); // [10, ["start", "done"]]
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
export type Logged<L, A> = WithValue<A> & WithLog<L>;
|
|
28
|
-
export declare namespace Logged {
|
|
29
|
-
/**
|
|
30
|
-
* Wraps a pure value into a `Logged` with an empty log.
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```ts
|
|
34
|
-
* Logged.make<string, number>(42); // { value: 42, log: [] }
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
const make: <W, A>(value: A) => Logged<W, A>;
|
|
38
|
-
/**
|
|
39
|
-
* Creates a `Logged` that records a single log entry and produces no
|
|
40
|
-
* meaningful value. Use this to append to the log inside a `chain`.
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```ts
|
|
44
|
-
* Logged.tell("operation completed"); // { value: undefined, log: ["operation completed"] }
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
const tell: <W>(entry: W) => Logged<W, undefined>;
|
|
48
|
-
/**
|
|
49
|
-
* Transforms the value inside a `Logged` without affecting the log.
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```ts
|
|
53
|
-
* pipe(
|
|
54
|
-
* Logged.make<string, number>(5),
|
|
55
|
-
* Logged.map(n => n * 2),
|
|
56
|
-
* ); // { value: 10, log: [] }
|
|
57
|
-
* ```
|
|
58
|
-
*/
|
|
59
|
-
const map: <W, A, B>(f: (a: A) => B) => (data: Logged<W, A>) => Logged<W, B>;
|
|
60
|
-
/**
|
|
61
|
-
* Sequences two `Logged` computations, concatenating their logs.
|
|
62
|
-
* The value from the first is passed to `f`; the resulting log entries are
|
|
63
|
-
* appended after the entries from the first.
|
|
64
|
-
*
|
|
65
|
-
* Data-last — the first computation is the data being piped.
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```ts
|
|
69
|
-
* const result = pipe(
|
|
70
|
-
* Logged.make<string, number>(1),
|
|
71
|
-
* Logged.chain(n => pipe(Logged.tell("step"), Logged.map(() => n + 1))),
|
|
72
|
-
* Logged.chain(n => pipe(Logged.tell("done"), Logged.map(() => n * 10))),
|
|
73
|
-
* );
|
|
74
|
-
*
|
|
75
|
-
* Logged.run(result); // [20, ["step", "done"]]
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
const chain: <W, A, B>(f: (a: A) => Logged<W, B>) => (data: Logged<W, A>) => Logged<W, B>;
|
|
79
|
-
/**
|
|
80
|
-
* Applies a function wrapped in a `Logged` to a value wrapped in a `Logged`,
|
|
81
|
-
* concatenating both logs.
|
|
82
|
-
*
|
|
83
|
-
* @example
|
|
84
|
-
* ```ts
|
|
85
|
-
* const fn: Logged<string, (n: number) => number> = {
|
|
86
|
-
* value: n => n * 2,
|
|
87
|
-
* log: ["fn-loaded"],
|
|
88
|
-
* };
|
|
89
|
-
* const arg: Logged<string, number> = { value: 5, log: ["arg-loaded"] };
|
|
90
|
-
*
|
|
91
|
-
* const result = pipe(fn, Logged.ap(arg));
|
|
92
|
-
* Logged.run(result); // [10, ["fn-loaded", "arg-loaded"]]
|
|
93
|
-
* ```
|
|
94
|
-
*/
|
|
95
|
-
const ap: <W, A>(arg: Logged<W, A>) => <B>(data: Logged<W, (a: A) => B>) => Logged<W, B>;
|
|
96
|
-
/**
|
|
97
|
-
* Runs a side effect on the value without changing the `Logged`.
|
|
98
|
-
* Useful for debugging or inspecting intermediate values.
|
|
99
|
-
*
|
|
100
|
-
* @example
|
|
101
|
-
* ```ts
|
|
102
|
-
* pipe(
|
|
103
|
-
* Logged.make<string, number>(42),
|
|
104
|
-
* Logged.tap(n => console.log("value:", n)),
|
|
105
|
-
* );
|
|
106
|
-
* ```
|
|
107
|
-
*/
|
|
108
|
-
const tap: <W, A>(f: (a: A) => void) => (data: Logged<W, A>) => Logged<W, A>;
|
|
109
|
-
/**
|
|
110
|
-
* Extracts the value and log as a `readonly [A, ReadonlyArray<W>]` tuple.
|
|
111
|
-
* Use this at the boundary where you need to consume both.
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* ```ts
|
|
115
|
-
* const result = pipe(
|
|
116
|
-
* Logged.make<string, number>(1),
|
|
117
|
-
* Logged.chain(n => pipe(Logged.tell("incremented"), Logged.map(() => n + 1))),
|
|
118
|
-
* );
|
|
119
|
-
*
|
|
120
|
-
* const [value, log] = Logged.run(result);
|
|
121
|
-
* // value = 2, log = ["incremented"]
|
|
122
|
-
* ```
|
|
123
|
-
*/
|
|
124
|
-
const run: <W, A>(data: Logged<W, A>) => readonly [A, ReadonlyArray<W>];
|
|
125
|
-
}
|
|
126
|
-
//# sourceMappingURL=Logged.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Logged.d.ts","sourceRoot":"","sources":["../../../src/src/Core/Logged.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAExD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAErD,yBAAiB,MAAM,CAAC;IACvB;;;;;;;OAOG;IACI,MAAM,IAAI,GAAI,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,KAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAyB,CAAC;IAE3E;;;;;;;;OAQG;IACI,MAAM,IAAI,GAAI,CAAC,EAAE,OAAO,CAAC,KAAG,MAAM,CAAC,CAAC,EAAE,SAAS,CAAyC,CAAC;IAEhG;;;;;;;;;;OAUG;IACI,MAAM,GAAG,GAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAG/E,CAAC;IAEH;;;;;;;;;;;;;;;;;OAiBG;IACI,MAAM,KAAK,GAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAG7F,CAAC;IAEF;;;;;;;;;;;;;;;OAeG;IACI,MAAM,EAAE,GAAI,CAAC,EAAE,CAAC,EAAE,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,KAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAG3F,CAAC;IAEH;;;;;;;;;;;OAWG;IACI,MAAM,GAAG,GAAI,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAGhF,CAAC;IAEF;;;;;;;;;;;;;;OAcG;IACI,MAAM,GAAG,GAAI,CAAC,EAAE,CAAC,EACvB,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAChB,SAAS,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAA2B,CAAC;CAC5D"}
|
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import { WithKind, WithValue } from "./InternalTypes.js";
|
|
2
|
-
import { Result } from "./Result.js";
|
|
3
|
-
/**
|
|
4
|
-
* Option represents an optional value: every Option is either Some (contains a value) or None (empty).
|
|
5
|
-
* Use Option instead of null/undefined to make optionality explicit and composable.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* const findUser = (id: string): Option<User> =>
|
|
10
|
-
* users.has(id) ? Option.some(users.get(id)!) : Option.none();
|
|
11
|
-
*
|
|
12
|
-
* pipe(
|
|
13
|
-
* findUser("123"),
|
|
14
|
-
* Option.map(user => user.name),
|
|
15
|
-
* Option.getOrElse(() => "Unknown")
|
|
16
|
-
* );
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
export type Option<T> = Some<T> | None;
|
|
20
|
-
export type Some<A> = WithKind<"Some"> & WithValue<A>;
|
|
21
|
-
export type None = WithKind<"None">;
|
|
22
|
-
export declare namespace Option {
|
|
23
|
-
/**
|
|
24
|
-
* Creates a Some containing the given value.
|
|
25
|
-
*/
|
|
26
|
-
const some: <A>(value: A) => Some<A>;
|
|
27
|
-
/**
|
|
28
|
-
* Type guard that checks if a Option is Some.
|
|
29
|
-
*/
|
|
30
|
-
const isSome: <A>(data: Option<A>) => data is Some<A>;
|
|
31
|
-
/**
|
|
32
|
-
* Creates a None (empty Option).
|
|
33
|
-
*/
|
|
34
|
-
const none: () => None;
|
|
35
|
-
/**
|
|
36
|
-
* Type guard that checks if a Option is None.
|
|
37
|
-
*/
|
|
38
|
-
const isNone: <A>(data: Option<A>) => data is None;
|
|
39
|
-
/**
|
|
40
|
-
* Creates a Option from a nullable value.
|
|
41
|
-
* Returns None if the value is null or undefined, Some otherwise.
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* ```ts
|
|
45
|
-
* Option.fromNullable(null); // None
|
|
46
|
-
* Option.fromNullable(42); // Some(42)
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
const fromNullable: <A>(value: A | null | undefined) => Option<A>;
|
|
50
|
-
/**
|
|
51
|
-
* Extracts the value from a Option, returning null if None.
|
|
52
|
-
*/
|
|
53
|
-
const toNullable: <A>(data: Option<A>) => A | null;
|
|
54
|
-
/**
|
|
55
|
-
* Extracts the value from a Option, returning undefined if None.
|
|
56
|
-
*/
|
|
57
|
-
const toUndefined: <A>(data: Option<A>) => A | undefined;
|
|
58
|
-
/**
|
|
59
|
-
* Creates a Option from a possibly undefined value.
|
|
60
|
-
* Returns None if undefined, Some otherwise.
|
|
61
|
-
*/
|
|
62
|
-
const fromUndefined: <A>(value: A | undefined) => Option<A>;
|
|
63
|
-
/**
|
|
64
|
-
* Converts an Option to a Result.
|
|
65
|
-
* Some becomes Ok, None becomes Err with the provided error.
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```ts
|
|
69
|
-
* pipe(
|
|
70
|
-
* Option.some(42),
|
|
71
|
-
* Option.toResult(() => "Value was missing")
|
|
72
|
-
* ); // Ok(42)
|
|
73
|
-
*
|
|
74
|
-
* pipe(
|
|
75
|
-
* Option.none(),
|
|
76
|
-
* Option.toResult(() => "Value was missing")
|
|
77
|
-
* ); // Err("Value was missing")
|
|
78
|
-
* ```
|
|
79
|
-
*/
|
|
80
|
-
const toResult: <E>(onNone: () => E) => <A>(data: Option<A>) => Result<E, A>;
|
|
81
|
-
/**
|
|
82
|
-
* Creates an Option from a Result.
|
|
83
|
-
* Ok becomes Some, Err becomes None (the error is discarded).
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* ```ts
|
|
87
|
-
* Option.fromResult(Result.ok(42)); // Some(42)
|
|
88
|
-
* Option.fromResult(Result.err("oops")); // None
|
|
89
|
-
* ```
|
|
90
|
-
*/
|
|
91
|
-
const fromResult: <E, A>(data: Result<E, A>) => Option<A>;
|
|
92
|
-
/**
|
|
93
|
-
* Transforms the value inside a Option if it exists.
|
|
94
|
-
*
|
|
95
|
-
* @example
|
|
96
|
-
* ```ts
|
|
97
|
-
* pipe(Option.some(5), Option.map(n => n * 2)); // Some(10)
|
|
98
|
-
* pipe(Option.none(), Option.map(n => n * 2)); // None
|
|
99
|
-
* ```
|
|
100
|
-
*/
|
|
101
|
-
const map: <A, B>(f: (a: A) => B) => (data: Option<A>) => Option<B>;
|
|
102
|
-
/**
|
|
103
|
-
* Chains Option computations. If the first is Some, passes the value to f.
|
|
104
|
-
* If the first is None, propagates None.
|
|
105
|
-
*
|
|
106
|
-
* @example
|
|
107
|
-
* ```ts
|
|
108
|
-
* const parseNumber = (s: string): Option<number> => {
|
|
109
|
-
* const n = parseInt(s, 10);
|
|
110
|
-
* return isNaN(n) ? Option.none() : Option.some(n);
|
|
111
|
-
* };
|
|
112
|
-
*
|
|
113
|
-
* pipe(Option.some("42"), Option.chain(parseNumber)); // Some(42)
|
|
114
|
-
* pipe(Option.some("abc"), Option.chain(parseNumber)); // None
|
|
115
|
-
* ```
|
|
116
|
-
*/
|
|
117
|
-
const chain: <A, B>(f: (a: A) => Option<B>) => (data: Option<A>) => Option<B>;
|
|
118
|
-
/**
|
|
119
|
-
* Extracts the value from a Option by providing handlers for both cases.
|
|
120
|
-
*
|
|
121
|
-
* @example
|
|
122
|
-
* ```ts
|
|
123
|
-
* pipe(
|
|
124
|
-
* Option.some(5),
|
|
125
|
-
* Option.fold(
|
|
126
|
-
* () => "No value",
|
|
127
|
-
* n => `Value: ${n}`
|
|
128
|
-
* )
|
|
129
|
-
* ); // "Value: 5"
|
|
130
|
-
* ```
|
|
131
|
-
*/
|
|
132
|
-
const fold: <A, B>(onNone: () => B, onSome: (a: A) => B) => (data: Option<A>) => B;
|
|
133
|
-
/**
|
|
134
|
-
* Pattern matches on a Option, returning the result of the matching case.
|
|
135
|
-
*
|
|
136
|
-
* @example
|
|
137
|
-
* ```ts
|
|
138
|
-
* pipe(
|
|
139
|
-
* optionUser,
|
|
140
|
-
* Option.match({
|
|
141
|
-
* some: user => `Hello, ${user.name}`,
|
|
142
|
-
* none: () => "Hello, stranger"
|
|
143
|
-
* })
|
|
144
|
-
* );
|
|
145
|
-
* ```
|
|
146
|
-
*/
|
|
147
|
-
const match: <A, B>(cases: {
|
|
148
|
-
none: () => B;
|
|
149
|
-
some: (a: A) => B;
|
|
150
|
-
}) => (data: Option<A>) => B;
|
|
151
|
-
/**
|
|
152
|
-
* Returns the value inside an Option, or a default value if None.
|
|
153
|
-
* The default is a thunk `() => B` — evaluated only when the Option is None.
|
|
154
|
-
* The default can be a different type, widening the result to `A | B`.
|
|
155
|
-
*
|
|
156
|
-
* @example
|
|
157
|
-
* ```ts
|
|
158
|
-
* pipe(Option.some(5), Option.getOrElse(() => 0)); // 5
|
|
159
|
-
* pipe(Option.none(), Option.getOrElse(() => 0)); // 0
|
|
160
|
-
* pipe(Option.none<string>(), Option.getOrElse(() => null)); // null — typed as string | null
|
|
161
|
-
* ```
|
|
162
|
-
*/
|
|
163
|
-
const getOrElse: <A, B>(defaultValue: () => B) => (data: Option<A>) => A | B;
|
|
164
|
-
/**
|
|
165
|
-
* Executes a side effect on the value without changing the Option.
|
|
166
|
-
* Useful for logging or debugging.
|
|
167
|
-
*
|
|
168
|
-
* @example
|
|
169
|
-
* ```ts
|
|
170
|
-
* pipe(
|
|
171
|
-
* Option.some(5),
|
|
172
|
-
* Option.tap(n => console.log("Value:", n)),
|
|
173
|
-
* Option.map(n => n * 2)
|
|
174
|
-
* );
|
|
175
|
-
* ```
|
|
176
|
-
*/
|
|
177
|
-
const tap: <A>(f: (a: A) => void) => (data: Option<A>) => Option<A>;
|
|
178
|
-
/**
|
|
179
|
-
* Filters a Option based on a predicate.
|
|
180
|
-
* Returns None if the predicate returns false or if the Option is already None.
|
|
181
|
-
*
|
|
182
|
-
* @example
|
|
183
|
-
* ```ts
|
|
184
|
-
* pipe(Option.some(5), Option.filter(n => n > 3)); // Some(5)
|
|
185
|
-
* pipe(Option.some(2), Option.filter(n => n > 3)); // None
|
|
186
|
-
* ```
|
|
187
|
-
*/
|
|
188
|
-
const filter: <A>(predicate: (a: A) => boolean) => (data: Option<A>) => Option<A>;
|
|
189
|
-
/**
|
|
190
|
-
* Recovers from a None by providing a fallback Option.
|
|
191
|
-
* The fallback can produce a different type, widening the result to `Option<A | B>`.
|
|
192
|
-
*/
|
|
193
|
-
const recover: <A, B>(fallback: () => Option<B>) => (data: Option<A>) => Option<A | B>;
|
|
194
|
-
/**
|
|
195
|
-
* Applies a function wrapped in a Option to a value wrapped in a Option.
|
|
196
|
-
*
|
|
197
|
-
* @example
|
|
198
|
-
* ```ts
|
|
199
|
-
* const add = (a: number) => (b: number) => a + b;
|
|
200
|
-
* pipe(
|
|
201
|
-
* Option.some(add),
|
|
202
|
-
* Option.ap(Option.some(5)),
|
|
203
|
-
* Option.ap(Option.some(3))
|
|
204
|
-
* ); // Some(8)
|
|
205
|
-
* ```
|
|
206
|
-
*/
|
|
207
|
-
const ap: <A>(arg: Option<A>) => <B>(data: Option<(a: A) => B>) => Option<B>;
|
|
208
|
-
}
|
|
209
|
-
//# sourceMappingURL=Option.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Option.d.ts","sourceRoot":"","sources":["../../../src/src/Core/Option.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;AAEvC,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;AACtD,MAAM,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;AAIpC,yBAAiB,MAAM,CAAC;IACvB;;OAEG;IACI,MAAM,IAAI,GAAI,CAAC,EAAE,OAAO,CAAC,KAAG,IAAI,CAAC,CAAC,CAA8B,CAAC;IAExE;;OAEG;IACI,MAAM,MAAM,GAAI,CAAC,EAAE,MAAM,MAAM,CAAC,CAAC,CAAC,KAAG,IAAI,IAAI,IAAI,CAAC,CAAC,CAAyB,CAAC;IAEpF;;OAEG;IACI,MAAM,IAAI,QAAO,IAAa,CAAC;IAEtC;;OAEG;IACI,MAAM,MAAM,GAAI,CAAC,EAAE,MAAM,MAAM,CAAC,CAAC,CAAC,KAAG,IAAI,IAAI,IAA4B,CAAC;IAEjF;;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AC,KAAG,MAAM,CAAC,CAAC,CACd,CAAC;CACpE"}
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { Option } from "./Option.js";
|
|
2
|
-
import type { Lens } from "./Lens.js";
|
|
3
|
-
/** Keys of T for which undefined is assignable (i.e. optional fields). */
|
|
4
|
-
type OptionalKeys<T> = {
|
|
5
|
-
[K in keyof T]-?: undefined extends T[K] ? K : never;
|
|
6
|
-
}[keyof T];
|
|
7
|
-
/**
|
|
8
|
-
* Optional<S, A> focuses on a value A inside a structure S that may or may
|
|
9
|
-
* not be present. Like a Lens, but get returns Option<A>.
|
|
10
|
-
*
|
|
11
|
-
* Compose with other Optionals via `andThen`, or with a Lens via `andThenLens`.
|
|
12
|
-
* Convert a Lens to an Optional with `Lens.toOptional`.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* type Profile = { username: string; bio?: string };
|
|
17
|
-
*
|
|
18
|
-
* const bioOpt = Optional.prop<Profile>()("bio");
|
|
19
|
-
*
|
|
20
|
-
* pipe(profile, Optional.get(bioOpt)); // Some("hello") or None
|
|
21
|
-
* pipe(profile, Optional.set(bioOpt)("hello")); // new Profile with bio set
|
|
22
|
-
* pipe(profile, Optional.modify(bioOpt)(s => s + "!")); // appends if present
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
export type Optional<S, A> = {
|
|
26
|
-
readonly get: (s: S) => Option<A>;
|
|
27
|
-
readonly set: (a: A) => (s: S) => S;
|
|
28
|
-
};
|
|
29
|
-
export declare namespace Optional {
|
|
30
|
-
/**
|
|
31
|
-
* Constructs an Optional from a getter (returning Option<A>) and a setter.
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```ts
|
|
35
|
-
* const firstChar = Optional.make(
|
|
36
|
-
* (s: string) => s.length > 0 ? Option.some(s[0]) : Option.none(),
|
|
37
|
-
* (c) => (s) => s.length > 0 ? c + s.slice(1) : s,
|
|
38
|
-
* );
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
const make: <S, A>(get: (s: S) => Option<A>, set: (a: A) => (s: S) => S) => Optional<S, A>;
|
|
42
|
-
/**
|
|
43
|
-
* Creates an Optional that focuses on an optional property of an object.
|
|
44
|
-
* Only keys whose type includes undefined (i.e. `field?: T`) are accepted.
|
|
45
|
-
* Call with the structure type first, then the key.
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```ts
|
|
49
|
-
* type Profile = { username: string; bio?: string };
|
|
50
|
-
* const bioOpt = Optional.prop<Profile>()("bio");
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
const prop: <S>() => <K extends OptionalKeys<S>>(key: K) => Optional<S, NonNullable<S[K]>>;
|
|
54
|
-
/**
|
|
55
|
-
* Creates an Optional that focuses on an element at a given index in an array.
|
|
56
|
-
* Returns None when the index is out of bounds; set is a no-op when out of bounds.
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* ```ts
|
|
60
|
-
* const firstItem = Optional.index<string>(0);
|
|
61
|
-
*
|
|
62
|
-
* pipe(["a", "b"], Optional.get(firstItem)); // Some("a")
|
|
63
|
-
* pipe([], Optional.get(firstItem)); // None
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
66
|
-
const index: <A>(i: number) => Optional<A[], A>;
|
|
67
|
-
/**
|
|
68
|
-
* Reads the focused value from a structure, returning Option<A>.
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```ts
|
|
72
|
-
* pipe(profile, Optional.get(bioOpt)); // Some("...") or None
|
|
73
|
-
* ```
|
|
74
|
-
*/
|
|
75
|
-
const get: <S, A>(opt: Optional<S, A>) => (s: S) => Option<A>;
|
|
76
|
-
/**
|
|
77
|
-
* Replaces the focused value within a structure.
|
|
78
|
-
* For indexed focuses, this is a no-op when the index is out of bounds.
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* ```ts
|
|
82
|
-
* pipe(profile, Optional.set(bioOpt)("hello"));
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
const set: <S, A>(opt: Optional<S, A>) => (a: A) => (s: S) => S;
|
|
86
|
-
/**
|
|
87
|
-
* Applies a function to the focused value if it is present; returns the
|
|
88
|
-
* structure unchanged if the focus is absent.
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```ts
|
|
92
|
-
* pipe(profile, Optional.modify(bioOpt)(s => s.toUpperCase()));
|
|
93
|
-
* ```
|
|
94
|
-
*/
|
|
95
|
-
const modify: <S, A>(opt: Optional<S, A>) => (f: (a: A) => A) => (s: S) => S;
|
|
96
|
-
/**
|
|
97
|
-
* Returns the focused value or a default when the focus is absent.
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* ```ts
|
|
101
|
-
* pipe(profile, Optional.getOrElse(bioOpt)(() => "no bio"));
|
|
102
|
-
* ```
|
|
103
|
-
*/
|
|
104
|
-
const getOrElse: <S, A>(opt: Optional<S, A>) => (defaultValue: () => A) => (s: S) => A;
|
|
105
|
-
/**
|
|
106
|
-
* Extracts a value from an Optional focus using handlers for the present
|
|
107
|
-
* and absent cases.
|
|
108
|
-
*
|
|
109
|
-
* @example
|
|
110
|
-
* ```ts
|
|
111
|
-
* pipe(profile, Optional.fold(bioOpt)(() => "no bio", (bio) => bio.toUpperCase()));
|
|
112
|
-
* ```
|
|
113
|
-
*/
|
|
114
|
-
const fold: <S, A>(opt: Optional<S, A>) => <B>(onNone: () => B, onSome: (a: A) => B) => (s: S) => B;
|
|
115
|
-
/**
|
|
116
|
-
* Pattern matches on an Optional focus using a named-case object.
|
|
117
|
-
*
|
|
118
|
-
* @example
|
|
119
|
-
* ```ts
|
|
120
|
-
* pipe(
|
|
121
|
-
* profile,
|
|
122
|
-
* Optional.match(bioOpt)({ none: () => "no bio", some: (bio) => bio }),
|
|
123
|
-
* );
|
|
124
|
-
* ```
|
|
125
|
-
*/
|
|
126
|
-
const match: <S, A>(opt: Optional<S, A>) => <B>(cases: {
|
|
127
|
-
none: () => B;
|
|
128
|
-
some: (a: A) => B;
|
|
129
|
-
}) => (s: S) => B;
|
|
130
|
-
/**
|
|
131
|
-
* Composes two Optionals: focuses through the outer, then through the inner.
|
|
132
|
-
* Returns None if either focus is absent.
|
|
133
|
-
*
|
|
134
|
-
* @example
|
|
135
|
-
* ```ts
|
|
136
|
-
* const deepOpt = pipe(
|
|
137
|
-
* Optional.prop<User>()("address"),
|
|
138
|
-
* Optional.andThen(Optional.prop<Address>()("landmark")),
|
|
139
|
-
* );
|
|
140
|
-
* ```
|
|
141
|
-
*/
|
|
142
|
-
const andThen: <A, B>(inner: Optional<A, B>) => <S>(outer: Optional<S, A>) => Optional<S, B>;
|
|
143
|
-
/**
|
|
144
|
-
* Composes an Optional with a Lens, producing an Optional.
|
|
145
|
-
* The Lens focuses within the value found by the Optional.
|
|
146
|
-
*
|
|
147
|
-
* @example
|
|
148
|
-
* ```ts
|
|
149
|
-
* const cityOpt = pipe(
|
|
150
|
-
* Optional.prop<User>()("address"),
|
|
151
|
-
* Optional.andThenLens(Lens.prop<Address>()("city")),
|
|
152
|
-
* );
|
|
153
|
-
* ```
|
|
154
|
-
*/
|
|
155
|
-
const andThenLens: <A, B>(inner: Lens<A, B>) => <S>(outer: Optional<S, A>) => Optional<S, B>;
|
|
156
|
-
}
|
|
157
|
-
export {};
|
|
158
|
-
//# sourceMappingURL=Optional.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Optional.d.ts","sourceRoot":"","sources":["../../../src/src/Core/Optional.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC,0EAA0E;AAC1E,KAAK,YAAY,CAAC,CAAC,IAAI;KACrB,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,SAAS,SAAS,CAAC,CAAC,CAAC,C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AE,CAAC,EAAE,OAAO,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,OAAO,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,QAAQ,CAAC,CAAC,EAAE,CAAC,CAU/F,CAAC;CACH"}
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { Refinement } from "./Refinement.js";
|
|
2
|
-
/**
|
|
3
|
-
* A boolean-valued function over a type `A`.
|
|
4
|
-
*
|
|
5
|
-
* A `Predicate<A>` is the simpler sibling of `Refinement<A, B>`: it tests whether a
|
|
6
|
-
* value satisfies a condition at runtime but carries no compile-time narrowing guarantee.
|
|
7
|
-
* Use it when you need to combine, negate, or adapt boolean checks as first-class values
|
|
8
|
-
* and do not require the extra type information that a `Refinement` provides.
|
|
9
|
-
*
|
|
10
|
-
* Every `Refinement<A, B>` is a `Predicate<A>` — convert with `Predicate.fromRefinement`
|
|
11
|
-
* when you want to compose a narrowing check alongside plain predicates.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* const isAdult: Predicate<number> = n => n >= 18;
|
|
16
|
-
* const isRetired: Predicate<number> = n => n >= 65;
|
|
17
|
-
*
|
|
18
|
-
* const isWorkingAge: Predicate<number> = pipe(
|
|
19
|
-
* isAdult,
|
|
20
|
-
* Predicate.and(Predicate.not(isRetired))
|
|
21
|
-
* );
|
|
22
|
-
*
|
|
23
|
-
* isWorkingAge(30); // true
|
|
24
|
-
* isWorkingAge(15); // false
|
|
25
|
-
* isWorkingAge(70); // false
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export type Predicate<A> = (a: A) => boolean;
|
|
29
|
-
export declare namespace Predicate {
|
|
30
|
-
/**
|
|
31
|
-
* Negates a predicate: the result passes exactly when the original fails.
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```ts
|
|
35
|
-
* const isBlank: Predicate<string> = s => s.trim().length === 0;
|
|
36
|
-
* const isNotBlank = Predicate.not(isBlank);
|
|
37
|
-
*
|
|
38
|
-
* isNotBlank("hello"); // true
|
|
39
|
-
* isNotBlank(" "); // false
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
const not: <A>(p: Predicate<A>) => Predicate<A>;
|
|
43
|
-
/**
|
|
44
|
-
* Combines two predicates with logical AND: passes only when both hold.
|
|
45
|
-
*
|
|
46
|
-
* Data-last — the first predicate is the data being piped.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```ts
|
|
50
|
-
* const isPositive: Predicate<number> = n => n > 0;
|
|
51
|
-
* const isEven: Predicate<number> = n => n % 2 === 0;
|
|
52
|
-
*
|
|
53
|
-
* const isPositiveEven: Predicate<number> = pipe(isPositive, Predicate.and(isEven));
|
|
54
|
-
*
|
|
55
|
-
* isPositiveEven(4); // true
|
|
56
|
-
* isPositiveEven(3); // false — positive but odd
|
|
57
|
-
* isPositiveEven(-2); // false — even but not positive
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
const and: <A>(second: Predicate<A>) => (first: Predicate<A>) => Predicate<A>;
|
|
61
|
-
/**
|
|
62
|
-
* Combines two predicates with logical OR: passes when either holds.
|
|
63
|
-
*
|
|
64
|
-
* Data-last — the first predicate is the data being piped.
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* ```ts
|
|
68
|
-
* const isChild: Predicate<number> = n => n < 13;
|
|
69
|
-
* const isSenior: Predicate<number> = n => n >= 65;
|
|
70
|
-
*
|
|
71
|
-
* const getsDiscount: Predicate<number> = pipe(isChild, Predicate.or(isSenior));
|
|
72
|
-
*
|
|
73
|
-
* getsDiscount(8); // true
|
|
74
|
-
* getsDiscount(70); // true
|
|
75
|
-
* getsDiscount(30); // false
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
const or: <A>(second: Predicate<A>) => (first: Predicate<A>) => Predicate<A>;
|
|
79
|
-
/**
|
|
80
|
-
* Adapts a `Predicate<A>` to work on a different input type `B` by applying `f`
|
|
81
|
-
* to extract the relevant `A` from a `B` before running the check.
|
|
82
|
-
*
|
|
83
|
-
* Data-last — the predicate is the data being piped; `f` is the extractor.
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* ```ts
|
|
87
|
-
* type User = { name: string; age: number };
|
|
88
|
-
*
|
|
89
|
-
* const isAdult: Predicate<number> = n => n >= 18;
|
|
90
|
-
*
|
|
91
|
-
* // Lift isAdult to work on Users by extracting the age field
|
|
92
|
-
* const isAdultUser: Predicate<User> = pipe(
|
|
93
|
-
* isAdult,
|
|
94
|
-
* Predicate.using((u: User) => u.age)
|
|
95
|
-
* );
|
|
96
|
-
*
|
|
97
|
-
* isAdultUser({ name: "Alice", age: 30 }); // true
|
|
98
|
-
* isAdultUser({ name: "Bob", age: 15 }); // false
|
|
99
|
-
* ```
|
|
100
|
-
*/
|
|
101
|
-
const using: <A, B>(f: (b: B) => A) => (p: Predicate<A>) => Predicate<B>;
|
|
102
|
-
/**
|
|
103
|
-
* Combines an array of predicates with AND: passes only when every predicate holds.
|
|
104
|
-
* Returns `true` for an empty array (vacuous truth).
|
|
105
|
-
*
|
|
106
|
-
* @example
|
|
107
|
-
* ```ts
|
|
108
|
-
* const checks: Predicate<string>[] = [
|
|
109
|
-
* s => s.length > 0,
|
|
110
|
-
* s => s.length <= 100,
|
|
111
|
-
* s => !s.includes("<"),
|
|
112
|
-
* ];
|
|
113
|
-
*
|
|
114
|
-
* Predicate.all(checks)("hello"); // true
|
|
115
|
-
* Predicate.all(checks)(""); // false — too short
|
|
116
|
-
* Predicate.all(checks)("<b>"); // false — contains "<"
|
|
117
|
-
* Predicate.all([])("anything"); // true
|
|
118
|
-
* ```
|
|
119
|
-
*/
|
|
120
|
-
const all: <A>(predicates: ReadonlyArray<Predicate<A>>) => Predicate<A>;
|
|
121
|
-
/**
|
|
122
|
-
* Combines an array of predicates with OR: passes when at least one holds.
|
|
123
|
-
* Returns `false` for an empty array.
|
|
124
|
-
*
|
|
125
|
-
* @example
|
|
126
|
-
* ```ts
|
|
127
|
-
* const acceptedFormats: Predicate<string>[] = [
|
|
128
|
-
* s => s.endsWith(".jpg"),
|
|
129
|
-
* s => s.endsWith(".png"),
|
|
130
|
-
* s => s.endsWith(".webp"),
|
|
131
|
-
* ];
|
|
132
|
-
*
|
|
133
|
-
* Predicate.any(acceptedFormats)("photo.jpg"); // true
|
|
134
|
-
* Predicate.any(acceptedFormats)("photo.gif"); // false
|
|
135
|
-
* Predicate.any([])("anything"); // false
|
|
136
|
-
* ```
|
|
137
|
-
*/
|
|
138
|
-
const any: <A>(predicates: ReadonlyArray<Predicate<A>>) => Predicate<A>;
|
|
139
|
-
/**
|
|
140
|
-
* Converts a `Refinement<A, B>` into a `Predicate<A>`, discarding the compile-time
|
|
141
|
-
* narrowing. Use this when you want to combine a type guard with plain predicates
|
|
142
|
-
* using `and`, `or`, or `all`.
|
|
143
|
-
*
|
|
144
|
-
* @example
|
|
145
|
-
* ```ts
|
|
146
|
-
* const isString: Refinement<unknown, string> =
|
|
147
|
-
* Refinement.make(x => typeof x === "string");
|
|
148
|
-
*
|
|
149
|
-
* const isShortString: Predicate<unknown> = pipe(
|
|
150
|
-
* Predicate.fromRefinement(isString),
|
|
151
|
-
* Predicate.and(x => (x as string).length < 10)
|
|
152
|
-
* );
|
|
153
|
-
*
|
|
154
|
-
* isShortString("hi"); // true
|
|
155
|
-
* isShortString("a very long string that exceeds ten characters"); // false
|
|
156
|
-
* isShortString(42); // false
|
|
157
|
-
* ```
|
|
158
|
-
*/
|
|
159
|
-
const fromRefinement: <A, B extends A>(r: Refinement<A, B>) => Predicate<A>;
|
|
160
|
-
}
|
|
161
|
-
//# sourceMappingURL=Predicate.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Predicate.d.ts","sourceRoot":"","sources":["../../../src/src/Core/Predicate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iB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