@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.
Files changed (193) hide show
  1. package/LICENCE +28 -0
  2. package/README.md +1 -1
  3. package/{types/src/Types/NonEmptyList.d.ts → dist/NonEmptyList-BlGFjor5.d.mts} +4 -3
  4. package/dist/NonEmptyList-BlGFjor5.d.ts +30 -0
  5. package/dist/Task-BB8Wmc1J.d.ts +677 -0
  6. package/dist/Task-ChKyH0pF.d.mts +677 -0
  7. package/dist/chunk-DBIC62UV.mjs +6 -0
  8. package/dist/chunk-QPTGO5AS.mjs +150 -0
  9. package/dist/composition.d.mts +495 -0
  10. package/dist/composition.d.ts +495 -0
  11. package/dist/composition.js +188 -0
  12. package/dist/composition.mjs +135 -0
  13. package/dist/core.d.mts +2170 -0
  14. package/dist/core.d.ts +2170 -0
  15. package/dist/core.js +698 -0
  16. package/dist/core.mjs +517 -0
  17. package/dist/types.d.mts +54 -0
  18. package/{types/src/Types/Brand.d.ts → dist/types.d.ts} +6 -4
  19. package/dist/types.js +41 -0
  20. package/dist/types.mjs +14 -0
  21. package/dist/utils.d.mts +1285 -0
  22. package/dist/utils.d.ts +1285 -0
  23. package/dist/utils.js +722 -0
  24. package/dist/utils.mjs +553 -0
  25. package/package.json +63 -69
  26. package/esm/mod.js +0 -3
  27. package/esm/package.json +0 -3
  28. package/esm/src/Composition/compose.js +0 -3
  29. package/esm/src/Composition/converge.js +0 -3
  30. package/esm/src/Composition/curry.js +0 -42
  31. package/esm/src/Composition/flip.js +0 -20
  32. package/esm/src/Composition/flow.js +0 -8
  33. package/esm/src/Composition/fn.js +0 -85
  34. package/esm/src/Composition/index.js +0 -13
  35. package/esm/src/Composition/juxt.js +0 -3
  36. package/esm/src/Composition/memoize.js +0 -66
  37. package/esm/src/Composition/not.js +0 -25
  38. package/esm/src/Composition/on.js +0 -12
  39. package/esm/src/Composition/pipe.js +0 -3
  40. package/esm/src/Composition/tap.js +0 -33
  41. package/esm/src/Composition/uncurry.js +0 -32
  42. package/esm/src/Core/Deferred.js +0 -30
  43. package/esm/src/Core/InternalTypes.js +0 -1
  44. package/esm/src/Core/Lens.js +0 -98
  45. package/esm/src/Core/Logged.js +0 -111
  46. package/esm/src/Core/Option.js +0 -191
  47. package/esm/src/Core/Optional.js +0 -160
  48. package/esm/src/Core/Predicate.js +0 -133
  49. package/esm/src/Core/Reader.js +0 -134
  50. package/esm/src/Core/Refinement.js +0 -115
  51. package/esm/src/Core/RemoteData.js +0 -211
  52. package/esm/src/Core/Result.js +0 -170
  53. package/esm/src/Core/State.js +0 -181
  54. package/esm/src/Core/Task.js +0 -223
  55. package/esm/src/Core/TaskOption.js +0 -106
  56. package/esm/src/Core/TaskResult.js +0 -127
  57. package/esm/src/Core/TaskValidation.js +0 -128
  58. package/esm/src/Core/These.js +0 -245
  59. package/esm/src/Core/Validation.js +0 -212
  60. package/esm/src/Core/index.js +0 -17
  61. package/esm/src/Types/Brand.js +0 -28
  62. package/esm/src/Types/NonEmptyList.js +0 -14
  63. package/esm/src/Types/index.js +0 -2
  64. package/esm/src/Utils/Arr.js +0 -570
  65. package/esm/src/Utils/Num.js +0 -124
  66. package/esm/src/Utils/Rec.js +0 -215
  67. package/esm/src/Utils/Str.js +0 -134
  68. package/esm/src/Utils/index.js +0 -4
  69. package/script/mod.js +0 -19
  70. package/script/package.json +0 -3
  71. package/script/src/Composition/compose.js +0 -6
  72. package/script/src/Composition/converge.js +0 -6
  73. package/script/src/Composition/curry.js +0 -48
  74. package/script/src/Composition/flip.js +0 -24
  75. package/script/src/Composition/flow.js +0 -11
  76. package/script/src/Composition/fn.js +0 -98
  77. package/script/src/Composition/index.js +0 -29
  78. package/script/src/Composition/juxt.js +0 -6
  79. package/script/src/Composition/memoize.js +0 -71
  80. package/script/src/Composition/not.js +0 -29
  81. package/script/src/Composition/on.js +0 -16
  82. package/script/src/Composition/pipe.js +0 -6
  83. package/script/src/Composition/tap.js +0 -37
  84. package/script/src/Composition/uncurry.js +0 -38
  85. package/script/src/Core/Deferred.js +0 -33
  86. package/script/src/Core/InternalTypes.js +0 -2
  87. package/script/src/Core/Lens.js +0 -101
  88. package/script/src/Core/Logged.js +0 -114
  89. package/script/src/Core/Option.js +0 -194
  90. package/script/src/Core/Optional.js +0 -163
  91. package/script/src/Core/Predicate.js +0 -136
  92. package/script/src/Core/Reader.js +0 -137
  93. package/script/src/Core/Refinement.js +0 -118
  94. package/script/src/Core/RemoteData.js +0 -214
  95. package/script/src/Core/Result.js +0 -173
  96. package/script/src/Core/State.js +0 -184
  97. package/script/src/Core/Task.js +0 -226
  98. package/script/src/Core/TaskOption.js +0 -109
  99. package/script/src/Core/TaskResult.js +0 -130
  100. package/script/src/Core/TaskValidation.js +0 -131
  101. package/script/src/Core/These.js +0 -248
  102. package/script/src/Core/Validation.js +0 -215
  103. package/script/src/Core/index.js +0 -33
  104. package/script/src/Types/Brand.js +0 -31
  105. package/script/src/Types/NonEmptyList.js +0 -18
  106. package/script/src/Types/index.js +0 -18
  107. package/script/src/Utils/Arr.js +0 -573
  108. package/script/src/Utils/Num.js +0 -127
  109. package/script/src/Utils/Rec.js +0 -218
  110. package/script/src/Utils/Str.js +0 -137
  111. package/script/src/Utils/index.js +0 -20
  112. package/types/mod.d.ts +0 -4
  113. package/types/mod.d.ts.map +0 -1
  114. package/types/src/Composition/compose.d.ts +0 -33
  115. package/types/src/Composition/compose.d.ts.map +0 -1
  116. package/types/src/Composition/converge.d.ts +0 -21
  117. package/types/src/Composition/converge.d.ts.map +0 -1
  118. package/types/src/Composition/curry.d.ts +0 -43
  119. package/types/src/Composition/curry.d.ts.map +0 -1
  120. package/types/src/Composition/flip.d.ts +0 -21
  121. package/types/src/Composition/flip.d.ts.map +0 -1
  122. package/types/src/Composition/flow.d.ts +0 -56
  123. package/types/src/Composition/flow.d.ts.map +0 -1
  124. package/types/src/Composition/fn.d.ts +0 -76
  125. package/types/src/Composition/fn.d.ts.map +0 -1
  126. package/types/src/Composition/index.d.ts +0 -14
  127. package/types/src/Composition/index.d.ts.map +0 -1
  128. package/types/src/Composition/juxt.d.ts +0 -18
  129. package/types/src/Composition/juxt.d.ts.map +0 -1
  130. package/types/src/Composition/memoize.d.ts +0 -46
  131. package/types/src/Composition/memoize.d.ts.map +0 -1
  132. package/types/src/Composition/not.d.ts +0 -26
  133. package/types/src/Composition/not.d.ts.map +0 -1
  134. package/types/src/Composition/on.d.ts +0 -13
  135. package/types/src/Composition/on.d.ts.map +0 -1
  136. package/types/src/Composition/pipe.d.ts +0 -56
  137. package/types/src/Composition/pipe.d.ts.map +0 -1
  138. package/types/src/Composition/tap.d.ts +0 -31
  139. package/types/src/Composition/tap.d.ts.map +0 -1
  140. package/types/src/Composition/uncurry.d.ts +0 -54
  141. package/types/src/Composition/uncurry.d.ts.map +0 -1
  142. package/types/src/Core/Deferred.d.ts +0 -49
  143. package/types/src/Core/Deferred.d.ts.map +0 -1
  144. package/types/src/Core/InternalTypes.d.ts +0 -23
  145. package/types/src/Core/InternalTypes.d.ts.map +0 -1
  146. package/types/src/Core/Lens.d.ts +0 -118
  147. package/types/src/Core/Lens.d.ts.map +0 -1
  148. package/types/src/Core/Logged.d.ts +0 -126
  149. package/types/src/Core/Logged.d.ts.map +0 -1
  150. package/types/src/Core/Option.d.ts +0 -209
  151. package/types/src/Core/Option.d.ts.map +0 -1
  152. package/types/src/Core/Optional.d.ts +0 -158
  153. package/types/src/Core/Optional.d.ts.map +0 -1
  154. package/types/src/Core/Predicate.d.ts +0 -161
  155. package/types/src/Core/Predicate.d.ts.map +0 -1
  156. package/types/src/Core/Reader.d.ts +0 -156
  157. package/types/src/Core/Reader.d.ts.map +0 -1
  158. package/types/src/Core/Refinement.d.ts +0 -138
  159. package/types/src/Core/Refinement.d.ts.map +0 -1
  160. package/types/src/Core/RemoteData.d.ts +0 -197
  161. package/types/src/Core/RemoteData.d.ts.map +0 -1
  162. package/types/src/Core/Result.d.ts +0 -182
  163. package/types/src/Core/Result.d.ts.map +0 -1
  164. package/types/src/Core/State.d.ts +0 -192
  165. package/types/src/Core/State.d.ts.map +0 -1
  166. package/types/src/Core/Task.d.ts +0 -219
  167. package/types/src/Core/Task.d.ts.map +0 -1
  168. package/types/src/Core/TaskOption.d.ts +0 -121
  169. package/types/src/Core/TaskOption.d.ts.map +0 -1
  170. package/types/src/Core/TaskResult.d.ts +0 -119
  171. package/types/src/Core/TaskResult.d.ts.map +0 -1
  172. package/types/src/Core/TaskValidation.d.ts +0 -144
  173. package/types/src/Core/TaskValidation.d.ts.map +0 -1
  174. package/types/src/Core/These.d.ts +0 -225
  175. package/types/src/Core/These.d.ts.map +0 -1
  176. package/types/src/Core/Validation.d.ts +0 -203
  177. package/types/src/Core/Validation.d.ts.map +0 -1
  178. package/types/src/Core/index.d.ts +0 -18
  179. package/types/src/Core/index.d.ts.map +0 -1
  180. package/types/src/Types/Brand.d.ts.map +0 -1
  181. package/types/src/Types/NonEmptyList.d.ts.map +0 -1
  182. package/types/src/Types/index.d.ts +0 -3
  183. package/types/src/Types/index.d.ts.map +0 -1
  184. package/types/src/Utils/Arr.d.ts +0 -403
  185. package/types/src/Utils/Arr.d.ts.map +0 -1
  186. package/types/src/Utils/Num.d.ts +0 -110
  187. package/types/src/Utils/Num.d.ts.map +0 -1
  188. package/types/src/Utils/Rec.d.ts +0 -143
  189. package/types/src/Utils/Rec.d.ts.map +0 -1
  190. package/types/src/Utils/Str.d.ts +0 -128
  191. package/types/src/Utils/Str.d.ts.map +0 -1
  192. package/types/src/Utils/index.d.ts +0 -5
  193. package/types/src/Utils/index.d.ts.map +0 -1
@@ -1,156 +0,0 @@
1
- /**
2
- * A computation that reads from a shared environment `R` and produces a value `A`.
3
- * Use Reader to thread a dependency (config, logger, DB pool) through a pipeline
4
- * without passing it explicitly to every function.
5
- *
6
- * @example
7
- * ```ts
8
- * type Config = { baseUrl: string; apiKey: string };
9
- *
10
- * const buildUrl = (path: string): Reader<Config, string> =>
11
- * (config) => `${config.baseUrl}${path}`;
12
- *
13
- * const withAuth = (url: string): Reader<Config, string> =>
14
- * (config) => `${url}?key=${config.apiKey}`;
15
- *
16
- * const fetchEndpoint = (path: string): Reader<Config, string> =>
17
- * pipe(
18
- * buildUrl(path),
19
- * Reader.chain(withAuth)
20
- * );
21
- *
22
- * // Inject the config once at the edge
23
- * fetchEndpoint("/users")(appConfig); // "https://api.example.com/users?key=secret"
24
- * ```
25
- */
26
- export type Reader<R, A> = (env: R) => A;
27
- export declare namespace Reader {
28
- /**
29
- * Lifts a pure value into a Reader. The environment is ignored.
30
- *
31
- * @example
32
- * ```ts
33
- * const always42: Reader<Config, number> = Reader.resolve(42);
34
- * always42(anyConfig); // 42
35
- * ```
36
- */
37
- const resolve: <R, A>(value: A) => Reader<R, A>;
38
- /**
39
- * Returns the full environment as the result.
40
- * The fundamental way to access the environment in a pipeline.
41
- *
42
- * @example
43
- * ```ts
44
- * pipe(
45
- * Reader.ask<Config>(),
46
- * Reader.map(config => config.baseUrl)
47
- * )(appConfig); // "https://api.example.com"
48
- * ```
49
- */
50
- const ask: <R>() => Reader<R, R>;
51
- /**
52
- * Projects a value from the environment using a selector function.
53
- * Equivalent to `pipe(Reader.ask(), Reader.map(f))` but more direct.
54
- *
55
- * @example
56
- * ```ts
57
- * const getBaseUrl: Reader<Config, string> = Reader.asks(c => c.baseUrl);
58
- * getBaseUrl(appConfig); // "https://api.example.com"
59
- * ```
60
- */
61
- const asks: <R, A>(f: (env: R) => A) => Reader<R, A>;
62
- /**
63
- * Transforms the value produced by a Reader.
64
- *
65
- * @example
66
- * ```ts
67
- * pipe(
68
- * Reader.asks((c: Config) => c.baseUrl),
69
- * Reader.map(url => url.toUpperCase())
70
- * )(appConfig); // "HTTPS://API.EXAMPLE.COM"
71
- * ```
72
- */
73
- const map: <R, A, B>(f: (a: A) => B) => (data: Reader<R, A>) => Reader<R, B>;
74
- /**
75
- * Sequences two Readers. Both see the same environment.
76
- * The output of the first is passed to `f`, which returns the next Reader.
77
- *
78
- * @example
79
- * ```ts
80
- * const buildUrl = (path: string): Reader<Config, string> =>
81
- * Reader.asks(c => `${c.baseUrl}${path}`);
82
- *
83
- * const addAuth = (url: string): Reader<Config, string> =>
84
- * Reader.asks(c => `${url}?key=${c.apiKey}`);
85
- *
86
- * pipe(
87
- * buildUrl("/items"),
88
- * Reader.chain(addAuth)
89
- * )(appConfig); // "https://api.example.com/items?key=secret"
90
- * ```
91
- */
92
- const chain: <R, A, B>(f: (a: A) => Reader<R, B>) => (data: Reader<R, A>) => Reader<R, B>;
93
- /**
94
- * Applies a function wrapped in a Reader to a value wrapped in a Reader.
95
- * Both Readers see the same environment.
96
- *
97
- * @example
98
- * ```ts
99
- * const add = (a: number) => (b: number) => a + b;
100
- * pipe(
101
- * Reader.resolve<Config, typeof add>(add),
102
- * Reader.ap(Reader.asks(c => c.timeout)),
103
- * Reader.ap(Reader.resolve(5))
104
- * )(appConfig);
105
- * ```
106
- */
107
- const ap: <R, A>(arg: Reader<R, A>) => <B>(data: Reader<R, (a: A) => B>) => Reader<R, B>;
108
- /**
109
- * Executes a side effect on the produced value without changing the Reader.
110
- * Useful for logging or debugging inside a pipeline.
111
- *
112
- * @example
113
- * ```ts
114
- * pipe(
115
- * buildUrl("/users"),
116
- * Reader.tap(url => console.log("Requesting:", url)),
117
- * Reader.chain(addAuth)
118
- * )(appConfig);
119
- * ```
120
- */
121
- const tap: <R, A>(f: (a: A) => void) => (data: Reader<R, A>) => Reader<R, A>;
122
- /**
123
- * Adapts a Reader to work with a different (typically wider) environment
124
- * by transforming the environment before passing it to the Reader.
125
- * This lets you compose Readers that expect different environments.
126
- *
127
- * @example
128
- * ```ts
129
- * type AppEnv = { db: DbPool; config: Config; logger: Logger };
130
- *
131
- * // buildUrl only needs Config
132
- * const buildUrl: Reader<Config, string> = Reader.asks(c => c.baseUrl);
133
- *
134
- * // Zoom in from AppEnv to Config
135
- * const buildUrlFromApp: Reader<AppEnv, string> =
136
- * pipe(buildUrl, Reader.local((env: AppEnv) => env.config));
137
- *
138
- * buildUrlFromApp(appEnv); // works with the full AppEnv
139
- * ```
140
- */
141
- const local: <R2, R>(f: (env: R2) => R) => <A>(data: Reader<R, A>) => Reader<R2, A>;
142
- /**
143
- * Runs a Reader by supplying the environment. Use this at the edge of your
144
- * program where the environment is available.
145
- *
146
- * @example
147
- * ```ts
148
- * pipe(
149
- * buildEndpoint("/users"),
150
- * Reader.run(appConfig)
151
- * ); // "https://api.example.com/users?key=secret"
152
- * ```
153
- */
154
- const run: <R>(env: R) => <A>(data: Reader<R, A>) => A;
155
- }
156
- //# sourceMappingURL=Reader.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Reader.d.ts","sourceRoot":"","sources":["../../../src/src/Core/Reader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;AAEzC,yBAAiB,MAAM,CAAC;IACvB;;;;;;;;OAQG;IACI,MAAM,OAAO,GAAI,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,KAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAoB,CAAC;IAEzE;;;;;;;;;;;OAWG;IACI,MAAM,GAAG,GAAI,CAAC,OAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAiB,CAAC;IAEvD;;;;;;;;;OASG;IACI,MAAM,IAAI,GAAI,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,KAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAoB,CAAC;IAE9E;;;;;;;;;;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,C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from `A` to `A is B` — a type predicate paired with a runtime check.
5
- *
6
- * A `Refinement<A, B>` proves at compile time that a value of type `A` is actually
7
- * the narrower type `B extends A`, backed by a runtime boolean test. Use it to
8
- * express domain invariants (non-empty strings, positive numbers, valid emails) as
9
- * first-class, composable values rather than one-off type guards scattered across
10
- * the codebase.
11
- *
12
- * @example
13
- * ```ts
14
- * type NonEmptyString = string & { readonly _tag: "NonEmptyString" };
15
- *
16
- * const isNonEmpty: Refinement<string, NonEmptyString> =
17
- * Refinement.make(s => s.length > 0);
18
- *
19
- * pipe(
20
- * "hello",
21
- * Refinement.toFilter(isNonEmpty)
22
- * ); // Some("hello")
23
- * ```
24
- */
25
- export type Refinement<A, B extends A> = (a: A) => a is B;
26
- export declare namespace Refinement {
27
- /**
28
- * Creates a `Refinement<A, B>` from a plain boolean predicate.
29
- *
30
- * This is an unsafe cast — the caller is responsible for ensuring that the
31
- * predicate truly characterises values of type `B`. Use this only when
32
- * bootstrapping a new refinement; prefer `compose`, `and`, or `or` to build
33
- * derived refinements from existing ones.
34
- *
35
- * @example
36
- * ```ts
37
- * type PositiveNumber = number & { readonly _tag: "PositiveNumber" };
38
- *
39
- * const isPositive: Refinement<number, PositiveNumber> =
40
- * Refinement.make(n => n > 0);
41
- * ```
42
- */
43
- const make: <A, B extends A>(f: (a: A) => boolean) => Refinement<A, B>;
44
- /**
45
- * Chains two refinements: if `ab` narrows `A` to `B` and `bc` narrows `B` to `C`,
46
- * the result narrows `A` directly to `C`.
47
- *
48
- * Data-last — the first refinement `ab` is the data being piped.
49
- *
50
- * @example
51
- * ```ts
52
- * type NonEmptyString = string & { readonly _tag: "NonEmpty" };
53
- * type TrimmedString = NonEmptyString & { readonly _tag: "Trimmed" };
54
- *
55
- * const isNonEmpty: Refinement<string, NonEmptyString> =
56
- * Refinement.make(s => s.length > 0);
57
- * const isTrimmed: Refinement<NonEmptyString, TrimmedString> =
58
- * Refinement.make(s => s === s.trim());
59
- *
60
- * const isNonEmptyTrimmed: Refinement<string, TrimmedString> = pipe(
61
- * isNonEmpty,
62
- * Refinement.compose(isTrimmed)
63
- * );
64
- * ```
65
- */
66
- const compose: <A, B extends A, C extends B>(bc: Refinement<B, C>) => (ab: Refinement<A, B>) => Refinement<A, C>;
67
- /**
68
- * Intersects two refinements: the result narrows `A` to `B & C`, passing only
69
- * when both refinements hold simultaneously.
70
- *
71
- * Data-last — the first refinement is the data being piped.
72
- *
73
- * @example
74
- * ```ts
75
- * const isString: Refinement<unknown, string> = Refinement.make(x => typeof x === "string");
76
- * const isNonEmpty: Refinement<unknown, { length: number }> =
77
- * Refinement.make(x => (x as any).length > 0);
78
- *
79
- * const isNonEmptyString = pipe(isString, Refinement.and(isNonEmpty));
80
- * isNonEmptyString("hi"); // true
81
- * isNonEmptyString(""); // false
82
- * ```
83
- */
84
- const and: <A, C extends A>(second: Refinement<A, C>) => <B extends A>(first: Refinement<A, B>) => Refinement<A, B & C>;
85
- /**
86
- * Unions two refinements: the result narrows `A` to `B | C`, passing when either
87
- * refinement holds.
88
- *
89
- * Data-last — the first refinement is the data being piped.
90
- *
91
- * @example
92
- * ```ts
93
- * const isString: Refinement<unknown, string> = Refinement.make(x => typeof x === "string");
94
- * const isNumber: Refinement<unknown, number> = Refinement.make(x => typeof x === "number");
95
- *
96
- * const isStringOrNumber = pipe(isString, Refinement.or(isNumber));
97
- * isStringOrNumber("hi"); // true
98
- * isStringOrNumber(42); // true
99
- * isStringOrNumber(true); // false
100
- * ```
101
- */
102
- const or: <A, C extends A>(second: Refinement<A, C>) => <B extends A>(first: Refinement<A, B>) => Refinement<A, B | C>;
103
- /**
104
- * Converts a `Refinement<A, B>` into a function `(a: A) => Option<B>`.
105
- *
106
- * Returns `Some(a)` when the refinement holds, `None` otherwise. Useful for
107
- * integrating runtime validation into an `Option`-based pipeline.
108
- *
109
- * @example
110
- * ```ts
111
- * type PositiveNumber = number & { readonly _tag: "Positive" };
112
- * const isPositive: Refinement<number, PositiveNumber> =
113
- * Refinement.make(n => n > 0);
114
- *
115
- * pipe(-1, Refinement.toFilter(isPositive)); // None
116
- * pipe(42, Refinement.toFilter(isPositive)); // Some(42)
117
- * ```
118
- */
119
- const toFilter: <A, B extends A>(r: Refinement<A, B>) => (a: A) => Option<B>;
120
- /**
121
- * Converts a `Refinement<A, B>` into a function `(a: A) => Result<E, B>`.
122
- *
123
- * Returns `Ok(a)` when the refinement holds, `Err(onFail(a))` otherwise. Use
124
- * this to surface validation failures as typed errors inside a `Result` pipeline.
125
- *
126
- * @example
127
- * ```ts
128
- * type NonEmptyString = string & { readonly _tag: "NonEmpty" };
129
- * const isNonEmpty: Refinement<string, NonEmptyString> =
130
- * Refinement.make(s => s.length > 0);
131
- *
132
- * pipe("", Refinement.toResult(isNonEmpty, () => "must not be empty")); // Err(...)
133
- * pipe("hi", Refinement.toResult(isNonEmpty, () => "must not be empty")); // Ok("hi")
134
- * ```
135
- */
136
- const toResult: <A, B extends A, E>(r: Refinement<A, B>, onFail: (a: A) => E) => (a: A) => Result<E, B>;
137
- }
138
- //# sourceMappingURL=Refinement.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Refinement.d.ts","sourceRoot":"","sources":["../../../src/src/Core/Refinement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAE1D,yBAAiB,UAAU,CAAC;IAC3B;;;;;;;;;;;;;;;OAeG;IACI,MAAM,IAAI,GAAI,CAAC,EAAE,CAAC,SAAS,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,OAAO,KAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAA0B,CAAC;IAEtG;;;;;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7C"}
@@ -1,197 +0,0 @@
1
- import { WithError, WithKind, WithValue } from "./InternalTypes.js";
2
- import { Option } from "./Option.js";
3
- import { Result } from "./Result.js";
4
- /**
5
- * RemoteData represents the state of an async data fetch.
6
- * It has four states: NotAsked, Loading, Failure, and Success.
7
- *
8
- * Use RemoteData to model data fetching states explicitly,
9
- * replacing the common `{ data: T | null; loading: boolean; error: Error | null }` pattern.
10
- *
11
- * @example
12
- * ```ts
13
- * const renderUser = pipe(
14
- * userData,
15
- * RemoteData.match({
16
- * notAsked: () => "Click to load",
17
- * loading: () => "Loading...",
18
- * failure: e => `Error: ${e.message}`,
19
- * success: user => `Hello, ${user.name}!`
20
- * })
21
- * );
22
- * ```
23
- */
24
- export type RemoteData<E, A> = NotAsked | Loading | Failure<E> | Success<A>;
25
- export type NotAsked = WithKind<"NotAsked">;
26
- export type Loading = WithKind<"Loading">;
27
- export type Failure<E> = WithKind<"Failure"> & WithError<E>;
28
- export type Success<A> = WithKind<"Success"> & WithValue<A>;
29
- export declare namespace RemoteData {
30
- /**
31
- * Creates a NotAsked RemoteData.
32
- */
33
- const notAsked: <E, A>() => RemoteData<E, A>;
34
- /**
35
- * Creates a Loading RemoteData.
36
- */
37
- const loading: <E, A>() => RemoteData<E, A>;
38
- /**
39
- * Creates a Failure RemoteData with the given error.
40
- */
41
- const failure: <E, A>(error: E) => RemoteData<E, A>;
42
- /**
43
- * Creates a Success RemoteData with the given value.
44
- */
45
- const success: <E, A>(value: A) => RemoteData<E, A>;
46
- /**
47
- * Type guard that checks if a RemoteData is NotAsked.
48
- */
49
- const isNotAsked: <E, A>(data: RemoteData<E, A>) => data is NotAsked;
50
- /**
51
- * Type guard that checks if a RemoteData is Loading.
52
- */
53
- const isLoading: <E, A>(data: RemoteData<E, A>) => data is Loading;
54
- /**
55
- * Type guard that checks if a RemoteData is Failure.
56
- */
57
- const isFailure: <E, A>(data: RemoteData<E, A>) => data is Failure<E>;
58
- /**
59
- * Type guard that checks if a RemoteData is Success.
60
- */
61
- const isSuccess: <E, A>(data: RemoteData<E, A>) => data is Success<A>;
62
- /**
63
- * Transforms the success value inside a RemoteData.
64
- *
65
- * @example
66
- * ```ts
67
- * pipe(RemoteData.success(5), RemoteData.map(n => n * 2)); // Success(10)
68
- * pipe(RemoteData.loading(), RemoteData.map(n => n * 2)); // Loading
69
- * ```
70
- */
71
- const map: <A, B>(f: (a: A) => B) => <E>(data: RemoteData<E, A>) => RemoteData<E, B>;
72
- /**
73
- * Transforms the error value inside a RemoteData.
74
- *
75
- * @example
76
- * ```ts
77
- * pipe(RemoteData.failure("oops"), RemoteData.mapError(e => e.toUpperCase())); // Failure("OOPS")
78
- * ```
79
- */
80
- const mapError: <E, F>(f: (e: E) => F) => <A>(data: RemoteData<E, A>) => RemoteData<F, A>;
81
- /**
82
- * Chains RemoteData computations. If the input is Success, passes the value to f.
83
- * Otherwise, propagates the current state.
84
- *
85
- * @example
86
- * ```ts
87
- * pipe(
88
- * RemoteData.success(5),
89
- * RemoteData.chain(n => n > 0 ? RemoteData.success(n) : RemoteData.failure("negative"))
90
- * );
91
- * ```
92
- */
93
- const chain: <E, A, B>(f: (a: A) => RemoteData<E, B>) => (data: RemoteData<E, A>) => RemoteData<E, B>;
94
- /**
95
- * Applies a function wrapped in a RemoteData to a value wrapped in a RemoteData.
96
- *
97
- * @example
98
- * ```ts
99
- * const add = (a: number) => (b: number) => a + b;
100
- * pipe(
101
- * RemoteData.success(add),
102
- * RemoteData.ap(RemoteData.success(5)),
103
- * RemoteData.ap(RemoteData.success(3))
104
- * ); // Success(8)
105
- * ```
106
- */
107
- const ap: <E, A>(arg: RemoteData<E, A>) => <B>(data: RemoteData<E, (a: A) => B>) => RemoteData<E, B>;
108
- /**
109
- * Extracts the value from a RemoteData by providing handlers for all four cases.
110
- *
111
- * @example
112
- * ```ts
113
- * pipe(
114
- * userData,
115
- * RemoteData.fold(
116
- * () => "Not asked",
117
- * () => "Loading...",
118
- * e => `Error: ${e}`,
119
- * value => `Got: ${value}`
120
- * )
121
- * );
122
- * ```
123
- */
124
- const fold: <E, A, B>(onNotAsked: () => B, onLoading: () => B, onFailure: (e: E) => B, onSuccess: (a: A) => B) => (data: RemoteData<E, A>) => B;
125
- /**
126
- * Pattern matches on a RemoteData, returning the result of the matching case.
127
- *
128
- * @example
129
- * ```ts
130
- * pipe(
131
- * userData,
132
- * RemoteData.match({
133
- * notAsked: () => "Click to load",
134
- * loading: () => "Loading...",
135
- * failure: e => `Error: ${e}`,
136
- * success: user => `Hello, ${user.name}!`
137
- * })
138
- * );
139
- * ```
140
- */
141
- const match: <E, A, B>(cases: {
142
- notAsked: () => B;
143
- loading: () => B;
144
- failure: (e: E) => B;
145
- success: (a: A) => B;
146
- }) => (data: RemoteData<E, A>) => B;
147
- /**
148
- * Returns the success value or a default value if the RemoteData is not Success.
149
- * The default can be a different type, widening the result to `A | B`.
150
- *
151
- * @example
152
- * ```ts
153
- * pipe(RemoteData.success(5), RemoteData.getOrElse(() => 0)); // 5
154
- * pipe(RemoteData.loading(), RemoteData.getOrElse(() => 0)); // 0
155
- * pipe(RemoteData.loading<string, number>(), RemoteData.getOrElse(() => null)); // null — typed as number | null
156
- * ```
157
- */
158
- const getOrElse: <E, A, B>(defaultValue: () => B) => (data: RemoteData<E, A>) => A | B;
159
- /**
160
- * Executes a side effect on the success value without changing the RemoteData.
161
- *
162
- * @example
163
- * ```ts
164
- * pipe(
165
- * RemoteData.success(5),
166
- * RemoteData.tap(n => console.log("Value:", n)),
167
- * RemoteData.map(n => n * 2)
168
- * );
169
- * ```
170
- */
171
- const tap: <E, A>(f: (a: A) => void) => (data: RemoteData<E, A>) => RemoteData<E, A>;
172
- /**
173
- * Recovers from a Failure state by providing a fallback RemoteData.
174
- * The fallback can produce a different success type, widening the result to `RemoteData<E, A | B>`.
175
- */
176
- const recover: <E, A, B>(fallback: (e: E) => RemoteData<E, B>) => (data: RemoteData<E, A>) => RemoteData<E, A | B>;
177
- /**
178
- * Converts a RemoteData to an Option.
179
- * Success becomes Some, all other states become None.
180
- */
181
- const toOption: <E, A>(data: RemoteData<E, A>) => Option<A>;
182
- /**
183
- * Converts a RemoteData to a Result.
184
- * Success becomes Ok, Failure becomes Err.
185
- * NotAsked and Loading become Err with the provided fallback error.
186
- *
187
- * @example
188
- * ```ts
189
- * pipe(
190
- * RemoteData.success(42),
191
- * RemoteData.toResult(() => "not loaded")
192
- * ); // Ok(42)
193
- * ```
194
- */
195
- const toResult: <E>(onNotReady: () => E) => <A>(data: RemoteData<E, A>) => Result<E, A>;
196
- }
197
- //# sourceMappingURL=RemoteData.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RemoteData.d.ts","sourceRoot":"","sources":["../../../src/src/Core/RemoteData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,IAAI,QAAQ,GAAG,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAE5E,MAAM,MAAM,QAAQ,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC;AAC5C,MAAM,MAAM,OAAO,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC;AAC1C,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,QAAQ,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;AAC5D,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,QAAQ,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;AAK5D,yBAAiB,UAAU,CAAC;IAC3B;;OAEG;IACI,MAAM,QAAQ,GAAI,CAAC,EAAE,CAAC,OA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