@nunofyobiz/effect-extras 1.0.0 → 2.1.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 (128) hide show
  1. package/README.md +50 -6
  2. package/dist/ArrayX.d.ts +415 -0
  3. package/dist/ArrayX.d.ts.map +1 -0
  4. package/dist/ArrayX.js +547 -0
  5. package/dist/ArrayX.js.map +1 -0
  6. package/dist/BigIntX.d.ts +24 -0
  7. package/dist/BigIntX.d.ts.map +1 -0
  8. package/dist/BigIntX.js +30 -0
  9. package/dist/BigIntX.js.map +1 -0
  10. package/dist/BooleanX.d.ts +25 -0
  11. package/dist/BooleanX.d.ts.map +1 -0
  12. package/dist/BooleanX.js +25 -0
  13. package/dist/BooleanX.js.map +1 -0
  14. package/dist/DurationX.d.ts +73 -0
  15. package/dist/DurationX.d.ts.map +1 -0
  16. package/dist/DurationX.js +91 -0
  17. package/dist/DurationX.js.map +1 -0
  18. package/dist/EffectX.d.ts +120 -0
  19. package/dist/EffectX.d.ts.map +1 -0
  20. package/dist/EffectX.js +140 -0
  21. package/dist/EffectX.js.map +1 -0
  22. package/dist/FormDataX.d.ts +49 -0
  23. package/dist/FormDataX.d.ts.map +1 -0
  24. package/dist/FormDataX.js +42 -0
  25. package/dist/FormDataX.js.map +1 -0
  26. package/dist/MapX.d.ts +32 -0
  27. package/dist/MapX.d.ts.map +1 -0
  28. package/dist/MapX.js +49 -0
  29. package/dist/MapX.js.map +1 -0
  30. package/dist/NonNullableX.d.ts +174 -0
  31. package/dist/NonNullableX.d.ts.map +1 -0
  32. package/dist/NonNullableX.js +212 -0
  33. package/dist/NonNullableX.js.map +1 -0
  34. package/dist/NumberX.d.ts +178 -0
  35. package/dist/NumberX.d.ts.map +1 -0
  36. package/dist/NumberX.js +214 -0
  37. package/dist/NumberX.js.map +1 -0
  38. package/dist/OptionX.d.ts +181 -0
  39. package/dist/OptionX.d.ts.map +1 -0
  40. package/dist/OptionX.js +195 -0
  41. package/dist/OptionX.js.map +1 -0
  42. package/dist/OrderX.d.ts +32 -0
  43. package/dist/OrderX.d.ts.map +1 -0
  44. package/dist/OrderX.js +32 -0
  45. package/dist/OrderX.js.map +1 -0
  46. package/dist/PredicateX.d.ts +76 -0
  47. package/dist/PredicateX.d.ts.map +1 -0
  48. package/dist/PredicateX.js +73 -0
  49. package/dist/PredicateX.js.map +1 -0
  50. package/dist/PromiseX.d.ts +32 -0
  51. package/dist/PromiseX.d.ts.map +1 -0
  52. package/dist/PromiseX.js +32 -0
  53. package/dist/PromiseX.js.map +1 -0
  54. package/dist/RecordX.d.ts +323 -0
  55. package/dist/RecordX.d.ts.map +1 -0
  56. package/dist/RecordX.js +326 -0
  57. package/dist/RecordX.js.map +1 -0
  58. package/dist/ResultX.d.ts +50 -0
  59. package/dist/ResultX.d.ts.map +1 -0
  60. package/dist/ResultX.js +50 -0
  61. package/dist/ResultX.js.map +1 -0
  62. package/dist/SchemaX.d.ts +249 -0
  63. package/dist/SchemaX.d.ts.map +1 -0
  64. package/dist/SchemaX.js +243 -0
  65. package/dist/SchemaX.js.map +1 -0
  66. package/dist/SetX.d.ts +121 -0
  67. package/dist/SetX.d.ts.map +1 -0
  68. package/dist/SetX.js +137 -0
  69. package/dist/SetX.js.map +1 -0
  70. package/dist/StringX.d.ts +70 -0
  71. package/dist/StringX.d.ts.map +1 -0
  72. package/dist/StringX.js +81 -0
  73. package/dist/StringX.js.map +1 -0
  74. package/dist/StructX.d.ts +219 -0
  75. package/dist/StructX.d.ts.map +1 -0
  76. package/dist/StructX.js +173 -0
  77. package/dist/StructX.js.map +1 -0
  78. package/dist/WarnResult.d.ts +1146 -0
  79. package/dist/WarnResult.d.ts.map +1 -0
  80. package/dist/WarnResult.js +1060 -0
  81. package/dist/WarnResult.js.map +1 -0
  82. package/dist/index.d.ts +22 -3703
  83. package/dist/index.d.ts.map +1 -0
  84. package/dist/index.js +21 -1005
  85. package/dist/index.js.map +1 -1
  86. package/package.json +18 -5
  87. package/src/{ArrayX/ArrayX.ts → ArrayX.ts} +29 -27
  88. package/src/{DurationX/DurationX.ts → DurationX.ts} +1 -1
  89. package/src/{RecordX/RecordX.ts → RecordX.ts} +1 -1
  90. package/src/WarnResult.ts +1265 -0
  91. package/src/index.ts +21 -20
  92. package/src/ArrayX/index.ts +0 -1
  93. package/src/BigIntX/index.ts +0 -1
  94. package/src/BooleanX/index.ts +0 -1
  95. package/src/DurationX/index.ts +0 -1
  96. package/src/EffectX/index.ts +0 -1
  97. package/src/FormDataX/index.ts +0 -1
  98. package/src/MapX/index.ts +0 -1
  99. package/src/NonNullableX/index.ts +0 -2
  100. package/src/NumberX/index.ts +0 -1
  101. package/src/OptionX/index.ts +0 -1
  102. package/src/OrderX/index.ts +0 -1
  103. package/src/PredicateX/index.ts +0 -1
  104. package/src/PromiseX/index.ts +0 -1
  105. package/src/RecordX/index.ts +0 -1
  106. package/src/ResultX/index.ts +0 -1
  107. package/src/SchemaX/index.ts +0 -1
  108. package/src/SetX/index.ts +0 -1
  109. package/src/StringX/index.ts +0 -1
  110. package/src/StructX/index.ts +0 -1
  111. package/src/These/These.ts +0 -1173
  112. package/src/These/index.ts +0 -1
  113. /package/src/{BigIntX/BigIntX.ts → BigIntX.ts} +0 -0
  114. /package/src/{BooleanX/BooleanX.ts → BooleanX.ts} +0 -0
  115. /package/src/{EffectX/EffectX.ts → EffectX.ts} +0 -0
  116. /package/src/{FormDataX/FormDataX.ts → FormDataX.ts} +0 -0
  117. /package/src/{MapX/MapX.ts → MapX.ts} +0 -0
  118. /package/src/{NonNullableX/NonNullableX.ts → NonNullableX.ts} +0 -0
  119. /package/src/{NumberX/NumberX.ts → NumberX.ts} +0 -0
  120. /package/src/{OptionX/OptionX.ts → OptionX.ts} +0 -0
  121. /package/src/{OrderX/OrderX.ts → OrderX.ts} +0 -0
  122. /package/src/{PredicateX/PredicateX.ts → PredicateX.ts} +0 -0
  123. /package/src/{PromiseX/PromiseX.ts → PromiseX.ts} +0 -0
  124. /package/src/{ResultX/ResultX.ts → ResultX.ts} +0 -0
  125. /package/src/{SchemaX/SchemaX.ts → SchemaX.ts} +0 -0
  126. /package/src/{SetX/SetX.ts → SetX.ts} +0 -0
  127. /package/src/{StringX/StringX.ts → StringX.ts} +0 -0
  128. /package/src/{StructX/StructX.ts → StructX.ts} +0 -0
@@ -0,0 +1,1146 @@
1
+ /**
2
+ * The `WarnResult` data type — a result that may carry a success value and/or
3
+ * warnings, where both sides are optional but never both absent.
4
+ *
5
+ * @since 0.0.0
6
+ */
7
+ import { Data, Effect, Option } from "effect";
8
+ /**
9
+ * A result that may come with a success value and may come with warnings — both
10
+ * are optional, but never both absent.
11
+ *
12
+ * Where `Result<A, E>` models an exclusive choice (success _or_ failure),
13
+ * `WarnResult` is an "inclusive or": the success value and the warnings can each
14
+ * be present independently. It is a tagged enum with three constructors:
15
+ * `SuccessOnly` (only a `success` value), `WarningsOnly` (only `warnings`), and
16
+ * `SuccessWithWarnings` (both). Reach for it when an operation can succeed, warn,
17
+ * or do both at once — e.g. a parse that yields a value _and_ a list of warnings,
18
+ * or that only produces warnings.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
23
+ *
24
+ * const both: WarnResult.WarnResult<string, number> =
25
+ * WarnResult.SuccessWithWarnings({
26
+ * warnings: "rounded down",
27
+ * success: 1
28
+ * })
29
+ *
30
+ * assert.deepStrictEqual(both._tag, "SuccessWithWarnings")
31
+ * ```
32
+ *
33
+ * @category models
34
+ * @since 0.0.0
35
+ */
36
+ export type WarnResult<W, A> = Data.TaggedEnum<{
37
+ WarningsOnly: {
38
+ readonly warnings: W;
39
+ };
40
+ SuccessOnly: {
41
+ readonly success: A;
42
+ };
43
+ SuccessWithWarnings: {
44
+ readonly warnings: W;
45
+ readonly success: A;
46
+ };
47
+ }>;
48
+ /**
49
+ * The `WarningsOnly` member of `WarnResult` — a result that carries only
50
+ * `warnings` and no `success` value.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
55
+ *
56
+ * const value: WarnResult.WarningsOnly<string> = WarnResult.WarningsOnly({
57
+ * warnings: "skipped 2 rows"
58
+ * })
59
+ *
60
+ * assert.deepStrictEqual(value.warnings, "skipped 2 rows")
61
+ * ```
62
+ *
63
+ * @category models
64
+ * @since 0.0.0
65
+ */
66
+ export type WarningsOnly<W> = WarnResult<W, never> & {
67
+ _tag: "WarningsOnly";
68
+ };
69
+ /**
70
+ * The `SuccessOnly` member of `WarnResult` — a result that carries only a
71
+ * `success` value and no `warnings`.
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
76
+ *
77
+ * const value: WarnResult.SuccessOnly<number> = WarnResult.SuccessOnly({
78
+ * success: 1
79
+ * })
80
+ *
81
+ * assert.deepStrictEqual(value.success, 1)
82
+ * ```
83
+ *
84
+ * @category models
85
+ * @since 0.0.0
86
+ */
87
+ export type SuccessOnly<A> = WarnResult<never, A> & {
88
+ _tag: "SuccessOnly";
89
+ };
90
+ /**
91
+ * The `SuccessWithWarnings` member of `WarnResult` — a result that carries both a
92
+ * `success` value and `warnings`.
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
97
+ *
98
+ * const value: WarnResult.SuccessWithWarnings<string, number> =
99
+ * WarnResult.SuccessWithWarnings({
100
+ * warnings: "rounded down",
101
+ * success: 1
102
+ * })
103
+ *
104
+ * assert.deepStrictEqual(value, {
105
+ * _tag: "SuccessWithWarnings",
106
+ * warnings: "rounded down",
107
+ * success: 1
108
+ * })
109
+ * ```
110
+ *
111
+ * @category models
112
+ * @since 0.0.0
113
+ */
114
+ export type SuccessWithWarnings<W, A> = WarnResult<W, A> & {
115
+ _tag: "SuccessWithWarnings";
116
+ };
117
+ /**
118
+ * Any `WarnResult` that is guaranteed to carry `warnings` — either `WarningsOnly`
119
+ * or `SuccessWithWarnings`.
120
+ *
121
+ * @example
122
+ * ```ts
123
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
124
+ *
125
+ * const value: WarnResult.WithWarnings<string, number> = WarnResult.WarningsOnly({
126
+ * warnings: "skipped 2 rows"
127
+ * })
128
+ *
129
+ * assert.deepStrictEqual(value.warnings, "skipped 2 rows")
130
+ * ```
131
+ *
132
+ * @category models
133
+ * @since 0.0.0
134
+ */
135
+ export type WithWarnings<W, A> = WarningsOnly<W> | SuccessWithWarnings<W, A>;
136
+ /**
137
+ * Any `WarnResult` that is guaranteed to carry a `success` value — either
138
+ * `SuccessOnly` or `SuccessWithWarnings`.
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
143
+ *
144
+ * const value: WarnResult.WithSuccess<string, number> = WarnResult.SuccessOnly({
145
+ * success: 1
146
+ * })
147
+ *
148
+ * assert.deepStrictEqual(value.success, 1)
149
+ * ```
150
+ *
151
+ * @category models
152
+ * @since 0.0.0
153
+ */
154
+ export type WithSuccess<W, A> = SuccessOnly<A> | SuccessWithWarnings<W, A>;
155
+ /**
156
+ * Constructs a `WarningsOnly` — a `WarnResult` that carries only `warnings`.
157
+ *
158
+ * @example
159
+ * ```ts
160
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
161
+ *
162
+ * const value = WarnResult.WarningsOnly({ warnings: "skipped 2 rows" })
163
+ *
164
+ * assert.deepStrictEqual(value._tag, "WarningsOnly")
165
+ * assert.deepStrictEqual(value.warnings, "skipped 2 rows")
166
+ * ```
167
+ *
168
+ * @category constructors
169
+ * @since 0.0.0
170
+ */
171
+ export declare const WarningsOnly: <A, B>(args: {
172
+ readonly warnings: A;
173
+ }) => {
174
+ readonly _tag: "WarningsOnly";
175
+ readonly warnings: A;
176
+ };
177
+ /**
178
+ * Constructs a `SuccessOnly` — a `WarnResult` that carries only a `success` value.
179
+ *
180
+ * @example
181
+ * ```ts
182
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
183
+ *
184
+ * const value = WarnResult.SuccessOnly({ success: 1 })
185
+ *
186
+ * assert.deepStrictEqual(value._tag, "SuccessOnly")
187
+ * assert.deepStrictEqual(value.success, 1)
188
+ * ```
189
+ *
190
+ * @category constructors
191
+ * @since 0.0.0
192
+ */
193
+ export declare const SuccessOnly: <A, B>(args: {
194
+ readonly success: B;
195
+ }) => {
196
+ readonly _tag: "SuccessOnly";
197
+ readonly success: B;
198
+ };
199
+ /**
200
+ * Constructs a `SuccessWithWarnings` — a `WarnResult` that carries both a
201
+ * `success` value and `warnings`.
202
+ *
203
+ * @example
204
+ * ```ts
205
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
206
+ *
207
+ * const value = WarnResult.SuccessWithWarnings({
208
+ * warnings: "rounded down",
209
+ * success: 1
210
+ * })
211
+ *
212
+ * assert.deepStrictEqual(value._tag, "SuccessWithWarnings")
213
+ * assert.deepStrictEqual(value.warnings, "rounded down")
214
+ * assert.deepStrictEqual(value.success, 1)
215
+ * ```
216
+ *
217
+ * @category constructors
218
+ * @since 0.0.0
219
+ */
220
+ export declare const SuccessWithWarnings: <A, B>(args: {
221
+ readonly warnings: A;
222
+ readonly success: B;
223
+ }) => {
224
+ readonly _tag: "SuccessWithWarnings";
225
+ readonly warnings: A;
226
+ readonly success: B;
227
+ };
228
+ /**
229
+ * Builds per-tag refinements for `WarnResult`. `is("WarningsOnly")` is a type
230
+ * guard that narrows a `WarnResult` to its `WarningsOnly` member, and likewise for
231
+ * `"SuccessOnly"` and `"SuccessWithWarnings"`.
232
+ *
233
+ * @example
234
+ * ```ts
235
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
236
+ *
237
+ * assert.deepStrictEqual(
238
+ * WarnResult.is("WarningsOnly")(WarnResult.WarningsOnly({ warnings: "w" })),
239
+ * true
240
+ * )
241
+ * assert.deepStrictEqual(
242
+ * WarnResult.is("WarningsOnly")(WarnResult.SuccessOnly({ success: 1 })),
243
+ * false
244
+ * )
245
+ * ```
246
+ *
247
+ * @category guards
248
+ * @since 0.0.0
249
+ */
250
+ export declare const is: <Tag extends "WarningsOnly" | "SuccessOnly" | "SuccessWithWarnings">(tag: Tag) => {
251
+ <T extends {
252
+ readonly _tag: "WarningsOnly";
253
+ readonly warnings: any;
254
+ } | {
255
+ readonly _tag: "SuccessOnly";
256
+ readonly success: any;
257
+ } | {
258
+ readonly _tag: "SuccessWithWarnings";
259
+ readonly warnings: any;
260
+ readonly success: any;
261
+ }>(u: T): u is T & {
262
+ readonly _tag: Tag;
263
+ };
264
+ (u: unknown): u is Extract<{
265
+ readonly _tag: "WarningsOnly";
266
+ readonly warnings: unknown;
267
+ }, {
268
+ readonly _tag: Tag;
269
+ }> | Extract<{
270
+ readonly _tag: "SuccessOnly";
271
+ readonly success: unknown;
272
+ }, {
273
+ readonly _tag: Tag;
274
+ }> | Extract<{
275
+ readonly _tag: "SuccessWithWarnings";
276
+ readonly warnings: unknown;
277
+ readonly success: unknown;
278
+ }, {
279
+ readonly _tag: Tag;
280
+ }>;
281
+ };
282
+ /**
283
+ * Folds a `WarnResult` over its three tags. Provide a handler for `WarningsOnly`,
284
+ * `SuccessOnly`, and `SuccessWithWarnings` and `match` returns a function from a
285
+ * `WarnResult` to the handlers' common result type.
286
+ *
287
+ * @example
288
+ * ```ts
289
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
290
+ *
291
+ * const describe = WarnResult.match({
292
+ * WarningsOnly: ({ warnings }) => `warnings ${warnings}`,
293
+ * SuccessOnly: ({ success }) => `success ${success}`,
294
+ * SuccessWithWarnings: ({ warnings, success }) => `both ${warnings}/${success}`
295
+ * })
296
+ *
297
+ * assert.deepStrictEqual(
298
+ * describe(WarnResult.SuccessWithWarnings({ warnings: "w", success: 1 })),
299
+ * "both w/1"
300
+ * )
301
+ * ```
302
+ *
303
+ * @category pattern matching
304
+ * @since 0.0.0
305
+ */
306
+ export declare const match: {
307
+ <A, B, C, D, Cases extends {
308
+ readonly WarningsOnly: (args: {
309
+ readonly _tag: "WarningsOnly";
310
+ readonly warnings: A;
311
+ }) => any;
312
+ readonly SuccessOnly: (args: {
313
+ readonly _tag: "SuccessOnly";
314
+ readonly success: B;
315
+ }) => any;
316
+ readonly SuccessWithWarnings: (args: {
317
+ readonly _tag: "SuccessWithWarnings";
318
+ readonly warnings: A;
319
+ readonly success: B;
320
+ }) => any;
321
+ }>(cases: Cases): (self: {
322
+ readonly _tag: "WarningsOnly";
323
+ readonly warnings: A;
324
+ } | {
325
+ readonly _tag: "SuccessOnly";
326
+ readonly success: B;
327
+ } | {
328
+ readonly _tag: "SuccessWithWarnings";
329
+ readonly warnings: A;
330
+ readonly success: B;
331
+ }) => import("effect/Unify").Unify<ReturnType<Cases["WarningsOnly" | "SuccessOnly" | "SuccessWithWarnings"]>>;
332
+ <A, B, C, D, Cases extends {
333
+ readonly WarningsOnly: (args: {
334
+ readonly _tag: "WarningsOnly";
335
+ readonly warnings: A;
336
+ }) => any;
337
+ readonly SuccessOnly: (args: {
338
+ readonly _tag: "SuccessOnly";
339
+ readonly success: B;
340
+ }) => any;
341
+ readonly SuccessWithWarnings: (args: {
342
+ readonly _tag: "SuccessWithWarnings";
343
+ readonly warnings: A;
344
+ readonly success: B;
345
+ }) => any;
346
+ }>(self: {
347
+ readonly _tag: "WarningsOnly";
348
+ readonly warnings: A;
349
+ } | {
350
+ readonly _tag: "SuccessOnly";
351
+ readonly success: B;
352
+ } | {
353
+ readonly _tag: "SuccessWithWarnings";
354
+ readonly warnings: A;
355
+ readonly success: B;
356
+ }, cases: Cases): import("effect/Unify").Unify<ReturnType<Cases["WarningsOnly" | "SuccessOnly" | "SuccessWithWarnings"]>>;
357
+ };
358
+ /**
359
+ * Builds a `WarnResult` known to carry `warnings`, choosing `SuccessWithWarnings`
360
+ * when a `success` value is present and `WarningsOnly` otherwise.
361
+ *
362
+ * Use it when the `warnings` are mandatory and the `success` value is an optional
363
+ * companion: pass an absent (`null`/`undefined`) `success` to get a
364
+ * `WarningsOnly`, or a present one to get a `SuccessWithWarnings`. The return type
365
+ * `WithWarnings<W, A>` reflects that `warnings` are always present.
366
+ *
367
+ * @example
368
+ * ```ts
369
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
370
+ *
371
+ * assert.deepStrictEqual(
372
+ * WarnResult.WithWarnings({ warnings: "w", success: 1 }),
373
+ * WarnResult.SuccessWithWarnings({ warnings: "w", success: 1 })
374
+ * )
375
+ *
376
+ * assert.deepStrictEqual(
377
+ * WarnResult.WithWarnings({ warnings: "w" }),
378
+ * WarnResult.WarningsOnly({ warnings: "w" })
379
+ * )
380
+ * ```
381
+ *
382
+ * @category constructors
383
+ * @since 0.0.0
384
+ */
385
+ export declare const WithWarnings: <W, A>({ warnings, success, }: {
386
+ warnings: W;
387
+ success?: A | undefined;
388
+ }) => WithWarnings<W, A>;
389
+ /**
390
+ * Builds a `WarnResult` known to carry a `success` value, choosing
391
+ * `SuccessWithWarnings` when `warnings` are present and `SuccessOnly` otherwise.
392
+ *
393
+ * The mirror of `WithWarnings`: the `success` value is mandatory and the
394
+ * `warnings` are an optional companion. Pass absent (`null`/`undefined`)
395
+ * `warnings` to get a `SuccessOnly`, or present ones to get a
396
+ * `SuccessWithWarnings`. The return type `WithSuccess<W, A>` reflects that a
397
+ * `success` value is always present.
398
+ *
399
+ * @example
400
+ * ```ts
401
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
402
+ *
403
+ * assert.deepStrictEqual(
404
+ * WarnResult.WithSuccess({ warnings: "w", success: 1 }),
405
+ * WarnResult.SuccessWithWarnings({ warnings: "w", success: 1 })
406
+ * )
407
+ *
408
+ * assert.deepStrictEqual(
409
+ * WarnResult.WithSuccess({ success: 1 }),
410
+ * WarnResult.SuccessOnly({ success: 1 })
411
+ * )
412
+ * ```
413
+ *
414
+ * @category constructors
415
+ * @since 0.0.0
416
+ */
417
+ export declare const WithSuccess: <W, A>({ warnings, success, }: {
418
+ warnings?: W | undefined;
419
+ success: A;
420
+ }) => WithSuccess<W, A>;
421
+ /**
422
+ * Builds a `WarnResult` from a pair of possibly-nullish inputs, wrapping the
423
+ * result in an `Option` so the all-absent case is expressible.
424
+ *
425
+ * Returns `Option.some(SuccessWithWarnings)` when both are present,
426
+ * `Option.some(WarningsOnly)` or `Option.some(SuccessOnly)` when exactly one is
427
+ * present, and `Option.none()` when both are nullish. Use it as the total entry
428
+ * point for turning an optional success value and optional warnings into a
429
+ * `WarnResult`.
430
+ *
431
+ * @example
432
+ * ```ts
433
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
434
+ * import { Option } from "effect"
435
+ *
436
+ * assert.deepStrictEqual(
437
+ * WarnResult.optionFromNullables({ warnings: "w", success: 1 }),
438
+ * Option.some(WarnResult.SuccessWithWarnings({ warnings: "w", success: 1 }))
439
+ * )
440
+ *
441
+ * assert.deepStrictEqual(
442
+ * WarnResult.optionFromNullables({ warnings: "w", success: null }),
443
+ * Option.some(WarnResult.WarningsOnly({ warnings: "w" }))
444
+ * )
445
+ *
446
+ * assert.deepStrictEqual(
447
+ * WarnResult.optionFromNullables({ warnings: null, success: undefined }),
448
+ * Option.none()
449
+ * )
450
+ * ```
451
+ *
452
+ * @category constructors
453
+ * @since 0.0.0
454
+ */
455
+ export declare const optionFromNullables: <W, A>({ warnings, success, }: {
456
+ warnings?: W | null | undefined;
457
+ success?: A | null | undefined;
458
+ }) => Option.Option<WarnResult<W, A>>;
459
+ /**
460
+ * Builds a `WarnResult` from a pair of possibly-nullish inputs, falling back to
461
+ * the `orElse` thunk when both are absent.
462
+ *
463
+ * The non-optional companion to `optionFromNullables`: it unwraps the same logic
464
+ * but resolves the all-absent case with `orElse` instead of an `Option`. The
465
+ * default `orElse` throws, so omit it only when at least one side is guaranteed
466
+ * present.
467
+ *
468
+ * @example
469
+ * ```ts
470
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
471
+ *
472
+ * assert.deepStrictEqual(
473
+ * WarnResult.fromNullables({ warnings: "w", success: 1 }),
474
+ * WarnResult.SuccessWithWarnings({ warnings: "w", success: 1 })
475
+ * )
476
+ *
477
+ * // Both absent — fall back via orElse instead of throwing
478
+ * assert.deepStrictEqual(
479
+ * WarnResult.fromNullables({
480
+ * warnings: null,
481
+ * success: null,
482
+ * orElse: () => WarnResult.WarningsOnly({ warnings: "none" })
483
+ * }),
484
+ * WarnResult.WarningsOnly({ warnings: "none" })
485
+ * )
486
+ * ```
487
+ *
488
+ * @category constructors
489
+ * @since 0.0.0
490
+ */
491
+ export declare const fromNullables: <W, A>({ warnings, success, orElse, }: {
492
+ warnings?: W | null | undefined;
493
+ success?: A | null | undefined;
494
+ orElse?: () => WarnResult<W, A>;
495
+ }) => WarnResult<W, A>;
496
+ /**
497
+ * Folds a `WarnResult` from the warnings' perspective, collapsing the three tags
498
+ * into two handlers.
499
+ *
500
+ * Both `WarningsOnly` and `SuccessWithWarnings` carry `warnings`, so they route to
501
+ * the `Warnings` handler; only `SuccessOnly` lacks `warnings` and routes to
502
+ * `SuccessOnly`. Use it when you care about the `warnings` and treat the
503
+ * success-only case as the exception.
504
+ *
505
+ * @example
506
+ * ```ts
507
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
508
+ *
509
+ * const onWarnings = WarnResult.matchWarnings({
510
+ * Warnings: (warnings: string) => `warnings ${warnings}`,
511
+ * SuccessOnly: (success: number) => `success ${success}`
512
+ * })
513
+ *
514
+ * assert.deepStrictEqual(
515
+ * onWarnings(WarnResult.WarningsOnly({ warnings: "w" })),
516
+ * "warnings w"
517
+ * )
518
+ * assert.deepStrictEqual(
519
+ * onWarnings(WarnResult.SuccessWithWarnings({ warnings: "w", success: 1 })),
520
+ * "warnings w"
521
+ * )
522
+ * assert.deepStrictEqual(
523
+ * onWarnings(WarnResult.SuccessOnly({ success: 1 })),
524
+ * "success 1"
525
+ * )
526
+ * ```
527
+ *
528
+ * @category pattern matching
529
+ * @since 0.0.0
530
+ */
531
+ export declare const matchWarnings: <W, A, Z>({ Warnings, SuccessOnly, }: {
532
+ Warnings: (warnings: W) => Z;
533
+ SuccessOnly: (success: A) => Z;
534
+ }) => (warnResult: WarnResult<W, A>) => Z;
535
+ /**
536
+ * Folds a `WarnResult` from the success value's perspective, collapsing the three
537
+ * tags into two handlers.
538
+ *
539
+ * The mirror of `matchWarnings`: both `SuccessOnly` and `SuccessWithWarnings`
540
+ * carry a `success` value, so they route to the `Success` handler; only
541
+ * `WarningsOnly` lacks a `success` value and routes to `WarningsOnly`. Use it when
542
+ * you care about the `success` value and treat the warnings-only case as the
543
+ * exception.
544
+ *
545
+ * @example
546
+ * ```ts
547
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
548
+ *
549
+ * const onSuccess = WarnResult.matchSuccess({
550
+ * WarningsOnly: (warnings: string) => `warnings ${warnings}`,
551
+ * Success: (success: number) => `success ${success}`
552
+ * })
553
+ *
554
+ * assert.deepStrictEqual(
555
+ * onSuccess(WarnResult.SuccessOnly({ success: 1 })),
556
+ * "success 1"
557
+ * )
558
+ * assert.deepStrictEqual(
559
+ * onSuccess(WarnResult.SuccessWithWarnings({ warnings: "w", success: 1 })),
560
+ * "success 1"
561
+ * )
562
+ * assert.deepStrictEqual(
563
+ * onSuccess(WarnResult.WarningsOnly({ warnings: "w" })),
564
+ * "warnings w"
565
+ * )
566
+ * ```
567
+ *
568
+ * @category pattern matching
569
+ * @since 0.0.0
570
+ */
571
+ export declare const matchSuccess: <W, A, Z>({ WarningsOnly, Success, }: {
572
+ WarningsOnly: (warnings: W) => Z;
573
+ Success: (success: A) => Z;
574
+ }) => (warnResult: WarnResult<W, A>) => Z;
575
+ /**
576
+ * Completes a `WarnResult` into a guaranteed `SuccessWithWarnings` by filling
577
+ * whichever side is missing from the matching `orElse` thunk.
578
+ *
579
+ * A `SuccessWithWarnings` passes through unchanged; a `WarningsOnly` gains a
580
+ * `success` value from `orElseSuccess`; a `SuccessOnly` gains `warnings` from
581
+ * `orElseWarnings`. Use it to normalise a partial `WarnResult` into the
582
+ * both-present shape before reading both sides.
583
+ *
584
+ * @example
585
+ * ```ts
586
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
587
+ *
588
+ * const fill = WarnResult.orElse({
589
+ * orElseWarnings: () => "no warnings",
590
+ * orElseSuccess: () => 0
591
+ * })
592
+ *
593
+ * assert.deepStrictEqual(
594
+ * fill(WarnResult.WarningsOnly({ warnings: "w" })),
595
+ * WarnResult.SuccessWithWarnings({ warnings: "w", success: 0 })
596
+ * )
597
+ * assert.deepStrictEqual(
598
+ * fill(WarnResult.SuccessOnly({ success: 1 })),
599
+ * WarnResult.SuccessWithWarnings({ warnings: "no warnings", success: 1 })
600
+ * )
601
+ * ```
602
+ *
603
+ * @category getters
604
+ * @since 0.0.0
605
+ */
606
+ export declare const orElse: <W2, A2>({ orElseWarnings, orElseSuccess, }: {
607
+ orElseWarnings: () => W2;
608
+ orElseSuccess: () => A2;
609
+ }) => (<W, A>(warnResult: WarnResult<W, A>) => SuccessWithWarnings<W | W2, A | A2>);
610
+ /**
611
+ * Completes a `WarnResult` into a `SuccessWithWarnings` whose missing side is
612
+ * filled with `undefined`.
613
+ *
614
+ * A specialisation of `orElse` that supplies `undefined` for whichever side is
615
+ * absent, so the result always exposes both `warnings` and `success` keys (each
616
+ * possibly `undefined`). Use it when you want to destructure both sides without
617
+ * branching on the tag.
618
+ *
619
+ * @example
620
+ * ```ts
621
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
622
+ *
623
+ * assert.deepStrictEqual(
624
+ * WarnResult.orUndefined(WarnResult.WarningsOnly({ warnings: "w" })),
625
+ * WarnResult.SuccessWithWarnings({ warnings: "w", success: undefined })
626
+ * )
627
+ * assert.deepStrictEqual(
628
+ * WarnResult.orUndefined(WarnResult.SuccessOnly({ success: 1 })),
629
+ * WarnResult.SuccessWithWarnings({ warnings: undefined, success: 1 })
630
+ * )
631
+ * ```
632
+ *
633
+ * @category getters
634
+ * @since 0.0.0
635
+ */
636
+ export declare const orUndefined: <W, A>(warnResult: {
637
+ readonly _tag: "WarningsOnly";
638
+ readonly warnings: W;
639
+ } | {
640
+ readonly _tag: "SuccessOnly";
641
+ readonly success: A;
642
+ } | {
643
+ readonly _tag: "SuccessWithWarnings";
644
+ readonly warnings: W;
645
+ readonly success: A;
646
+ }) => {
647
+ readonly _tag: "SuccessWithWarnings";
648
+ readonly warnings: W | undefined;
649
+ readonly success: A | undefined;
650
+ } & {
651
+ _tag: "SuccessWithWarnings";
652
+ };
653
+ /**
654
+ * Extracts the `warnings` of a `WarnResult`, falling back to `orElseReturn` when
655
+ * no `warnings` are present.
656
+ *
657
+ * `WarningsOnly` and `SuccessWithWarnings` return their `warnings`; `SuccessOnly`
658
+ * returns the result of `orElseReturn`. Use it to read the warnings with a default
659
+ * in one step.
660
+ *
661
+ * @example
662
+ * ```ts
663
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
664
+ *
665
+ * const warningsOrNone = WarnResult.warningsOrElse(() => "no warnings")
666
+ *
667
+ * assert.deepStrictEqual(
668
+ * warningsOrNone(WarnResult.WarningsOnly({ warnings: "w" })),
669
+ * "w"
670
+ * )
671
+ * assert.deepStrictEqual(
672
+ * warningsOrNone(WarnResult.SuccessWithWarnings({ warnings: "w", success: 1 })),
673
+ * "w"
674
+ * )
675
+ * assert.deepStrictEqual(
676
+ * warningsOrNone(WarnResult.SuccessOnly({ success: 1 })),
677
+ * "no warnings"
678
+ * )
679
+ * ```
680
+ *
681
+ * @category getters
682
+ * @since 0.0.0
683
+ */
684
+ export declare const warningsOrElse: <Z>(orElseReturn: () => Z) => <W, A>(warnResult: WarnResult<W, A>) => W | Z;
685
+ /**
686
+ * Extracts the `warnings` of a `WarnResult`, returning `undefined` when no
687
+ * `warnings` are present.
688
+ *
689
+ * A specialisation of `warningsOrElse` whose fallback is `undefined`:
690
+ * `WarningsOnly` and `SuccessWithWarnings` yield their `warnings`, while
691
+ * `SuccessOnly` yields `undefined`.
692
+ *
693
+ * @example
694
+ * ```ts
695
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
696
+ *
697
+ * assert.deepStrictEqual(
698
+ * WarnResult.warningsOrUndefined(WarnResult.WarningsOnly({ warnings: "w" })),
699
+ * "w"
700
+ * )
701
+ * assert.deepStrictEqual(
702
+ * WarnResult.warningsOrUndefined(WarnResult.SuccessOnly({ success: 1 })),
703
+ * undefined
704
+ * )
705
+ * ```
706
+ *
707
+ * @category getters
708
+ * @since 0.0.0
709
+ */
710
+ export declare const warningsOrUndefined: <W, A>(warnResult: {
711
+ readonly _tag: "WarningsOnly";
712
+ readonly warnings: W;
713
+ } | {
714
+ readonly _tag: "SuccessOnly";
715
+ readonly success: A;
716
+ } | {
717
+ readonly _tag: "SuccessWithWarnings";
718
+ readonly warnings: W;
719
+ readonly success: A;
720
+ }) => W | undefined;
721
+ /**
722
+ * Extracts the `success` value of a `WarnResult`, falling back to `orElseReturn`
723
+ * when no `success` value is present.
724
+ *
725
+ * The mirror of `warningsOrElse`: `SuccessOnly` and `SuccessWithWarnings` return
726
+ * their `success` value; `WarningsOnly` returns the result of `orElseReturn`.
727
+ *
728
+ * @example
729
+ * ```ts
730
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
731
+ *
732
+ * const successOrZero = WarnResult.successOrElse(() => 0)
733
+ *
734
+ * assert.deepStrictEqual(
735
+ * successOrZero(WarnResult.SuccessOnly({ success: 1 })),
736
+ * 1
737
+ * )
738
+ * assert.deepStrictEqual(
739
+ * successOrZero(WarnResult.WarningsOnly({ warnings: "w" })),
740
+ * 0
741
+ * )
742
+ * ```
743
+ *
744
+ * @category getters
745
+ * @since 0.0.0
746
+ */
747
+ export declare const successOrElse: <Z>(orElseReturn: () => Z) => <W, A>(warnResult: WarnResult<W, A>) => A | Z;
748
+ /**
749
+ * Extracts the `success` value of a `WarnResult`, returning `undefined` when no
750
+ * `success` value is present.
751
+ *
752
+ * A specialisation of `successOrElse` whose fallback is `undefined`: `SuccessOnly`
753
+ * and `SuccessWithWarnings` yield their `success` value, while `WarningsOnly`
754
+ * yields `undefined`.
755
+ *
756
+ * @example
757
+ * ```ts
758
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
759
+ *
760
+ * assert.deepStrictEqual(
761
+ * WarnResult.successOrUndefined(WarnResult.SuccessOnly({ success: 1 })),
762
+ * 1
763
+ * )
764
+ * assert.deepStrictEqual(
765
+ * WarnResult.successOrUndefined(WarnResult.WarningsOnly({ warnings: "w" })),
766
+ * undefined
767
+ * )
768
+ * ```
769
+ *
770
+ * @category getters
771
+ * @since 0.0.0
772
+ */
773
+ export declare const successOrUndefined: <W, A>(warnResult: {
774
+ readonly _tag: "WarningsOnly";
775
+ readonly warnings: W;
776
+ } | {
777
+ readonly _tag: "SuccessOnly";
778
+ readonly success: A;
779
+ } | {
780
+ readonly _tag: "SuccessWithWarnings";
781
+ readonly warnings: W;
782
+ readonly success: A;
783
+ }) => A | undefined;
784
+ /**
785
+ * Extracts the `success` value of a `WarnResult` as an `Option`.
786
+ *
787
+ * `SuccessOnly` and `SuccessWithWarnings` yield `Option.some(success)`;
788
+ * `WarningsOnly` yields `Option.none()`. Use it when you want to chain the success
789
+ * value through `Option` combinators rather than fall back to a default eagerly.
790
+ *
791
+ * @example
792
+ * ```ts
793
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
794
+ * import { Option } from "effect"
795
+ *
796
+ * assert.deepStrictEqual(
797
+ * WarnResult.successOption(WarnResult.SuccessOnly({ success: 1 })),
798
+ * Option.some(1)
799
+ * )
800
+ * assert.deepStrictEqual(
801
+ * WarnResult.successOption(WarnResult.WarningsOnly({ warnings: "w" })),
802
+ * Option.none()
803
+ * )
804
+ * ```
805
+ *
806
+ * @category getters
807
+ * @since 0.0.0
808
+ */
809
+ export declare const successOption: <W, A>(warnResult: WarnResult<W, A>) => Option.Option<A>;
810
+ /**
811
+ * Extracts the `warnings` of a `WarnResult` as an `Option`.
812
+ *
813
+ * The mirror of `successOption`: `WarningsOnly` and `SuccessWithWarnings` yield
814
+ * `Option.some(warnings)`, while `SuccessOnly` yields `Option.none()`.
815
+ *
816
+ * @example
817
+ * ```ts
818
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
819
+ * import { Option } from "effect"
820
+ *
821
+ * assert.deepStrictEqual(
822
+ * WarnResult.warningsOption(WarnResult.WarningsOnly({ warnings: "w" })),
823
+ * Option.some("w")
824
+ * )
825
+ * assert.deepStrictEqual(
826
+ * WarnResult.warningsOption(WarnResult.SuccessOnly({ success: 1 })),
827
+ * Option.none()
828
+ * )
829
+ * ```
830
+ *
831
+ * @category getters
832
+ * @since 0.0.0
833
+ */
834
+ export declare const warningsOption: <W, A>(warnResult: WarnResult<W, A>) => Option.Option<W>;
835
+ /**
836
+ * Transforms both sides of a `WarnResult`, applying `mapWarnings` to any
837
+ * `warnings` and `mapSuccess` to any `success` value.
838
+ *
839
+ * Each constructor is rebuilt with its mapped contents, so `WarningsOnly` maps
840
+ * only the warnings, `SuccessOnly` only the success value, and
841
+ * `SuccessWithWarnings` both. The tag is preserved. Use it as the bifunctor map
842
+ * over `WarnResult`.
843
+ *
844
+ * @example
845
+ * ```ts
846
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
847
+ *
848
+ * const both = WarnResult.mapBoth({
849
+ * mapWarnings: (warnings: string) => warnings.toUpperCase(),
850
+ * mapSuccess: (success: number) => success + 1
851
+ * })
852
+ *
853
+ * assert.deepStrictEqual(
854
+ * both(WarnResult.SuccessWithWarnings({ warnings: "w", success: 1 })),
855
+ * WarnResult.SuccessWithWarnings({ warnings: "W", success: 2 })
856
+ * )
857
+ * assert.deepStrictEqual(
858
+ * both(WarnResult.WarningsOnly({ warnings: "w" })),
859
+ * WarnResult.WarningsOnly({ warnings: "W" })
860
+ * )
861
+ * ```
862
+ *
863
+ * @category mapping
864
+ * @since 0.0.0
865
+ */
866
+ export declare const mapBoth: <W1, A1, W2, A2>({ mapWarnings, mapSuccess, }: {
867
+ mapWarnings: (warnings: W1) => W2;
868
+ mapSuccess: (success: A1) => A2;
869
+ }) => ((warnResult: WarnResult<W1, A1>) => WarnResult<W2, A2>);
870
+ /**
871
+ * Effectful `mapBoth`: transforms each present side through an `Effect`,
872
+ * reassembling the results into a `WarnResult` inside an `Effect`.
873
+ *
874
+ * For `SuccessWithWarnings` both effects run via `Effect.all` and their results
875
+ * are combined; `WarningsOnly`/`SuccessOnly` run only the relevant effect. Errors
876
+ * and requirements from both mappers are unioned into the result type. Use it when
877
+ * mapping a `WarnResult`'s sides requires effects (validation, IO).
878
+ *
879
+ * @example
880
+ * ```ts
881
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
882
+ * import { Effect } from "effect"
883
+ *
884
+ * const both = WarnResult.mapBothEffect({
885
+ * mapWarnings: (warnings: string) => Effect.succeed(warnings.toUpperCase()),
886
+ * mapSuccess: (success: number) => Effect.succeed(success + 1)
887
+ * })
888
+ *
889
+ * assert.deepStrictEqual(
890
+ * Effect.runSync(
891
+ * both(WarnResult.SuccessWithWarnings({ warnings: "w", success: 1 }))
892
+ * ),
893
+ * WarnResult.SuccessWithWarnings({ warnings: "W", success: 2 })
894
+ * )
895
+ * ```
896
+ *
897
+ * @category sequencing
898
+ * @since 0.0.0
899
+ */
900
+ export declare const mapBothEffect: <W1, A1, W2, A2, EW, EA, RW, RA>({ mapWarnings, mapSuccess, }: {
901
+ mapWarnings: (warnings: W1) => Effect.Effect<W2, EW, RW>;
902
+ mapSuccess: (success: A1) => Effect.Effect<A2, EA, RA>;
903
+ }) => ((warnResult: WarnResult<W1, A1>) => Effect.Effect<WarnResult<W2, A2>, EW | EA, RW | RA>);
904
+ /**
905
+ * Transforms the `warnings` of a `WarnResult`, leaving any `success` value
906
+ * untouched.
907
+ *
908
+ * A specialisation of `mapBoth` with the success mapper set to `identity`:
909
+ * `WarningsOnly` and `SuccessWithWarnings` have their `warnings` mapped, while
910
+ * `SuccessOnly` passes through unchanged.
911
+ *
912
+ * @example
913
+ * ```ts
914
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
915
+ *
916
+ * const shout = WarnResult.mapWarnings((warnings: string) =>
917
+ * warnings.toUpperCase()
918
+ * )
919
+ *
920
+ * assert.deepStrictEqual(
921
+ * shout(WarnResult.SuccessWithWarnings({ warnings: "w", success: 1 })),
922
+ * WarnResult.SuccessWithWarnings({ warnings: "W", success: 1 })
923
+ * )
924
+ * assert.deepStrictEqual(
925
+ * shout(WarnResult.SuccessOnly({ success: 1 })),
926
+ * WarnResult.SuccessOnly({ success: 1 })
927
+ * )
928
+ * ```
929
+ *
930
+ * @category mapping
931
+ * @since 0.0.0
932
+ */
933
+ export declare const mapWarnings: <W1, W2>(mapWarnings: (warnings: W1) => W2) => (<A>(warnResult: WarnResult<W1, A>) => WarnResult<W2, A>);
934
+ /**
935
+ * Chains the `warnings` of a `WarnResult` into a new `WarnResult`, flattening the
936
+ * result.
937
+ *
938
+ * Whenever `warnings` are present (`WarningsOnly` or `SuccessWithWarnings`) they
939
+ * are passed to `mapWarnings`, whose returned `WarnResult` replaces the original;
940
+ * `SuccessOnly` passes through unchanged. Use it to sequence warnings-driven
941
+ * computations that themselves produce a `WarnResult`.
942
+ *
943
+ * @example
944
+ * ```ts
945
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
946
+ *
947
+ * const chain = WarnResult.flatMapWarnings((warnings: string) =>
948
+ * warnings.length > 0
949
+ * ? WarnResult.WarningsOnly({ warnings: warnings.toUpperCase() })
950
+ * : WarnResult.SuccessOnly({ success: 0 })
951
+ * )
952
+ *
953
+ * assert.deepStrictEqual(
954
+ * chain(WarnResult.WarningsOnly({ warnings: "w" })),
955
+ * WarnResult.WarningsOnly({ warnings: "W" })
956
+ * )
957
+ * assert.deepStrictEqual(
958
+ * chain(WarnResult.SuccessOnly({ success: 1 })),
959
+ * WarnResult.SuccessOnly({ success: 1 })
960
+ * )
961
+ * ```
962
+ *
963
+ * @category sequencing
964
+ * @since 0.0.0
965
+ */
966
+ export declare const flatMapWarnings: <W1, W2, A2>(mapWarnings: (warnings: W1) => WarnResult<W2, A2>) => (<A1>(warnResult: WarnResult<W1, A1>) => WarnResult<W2, A1 | A2>);
967
+ /**
968
+ * Effectful `mapWarnings`: transforms the `warnings` of a `WarnResult` through an
969
+ * `Effect`, leaving any `success` value untouched.
970
+ *
971
+ * A specialisation of `mapBothEffect` with the success mapper set to
972
+ * `Effect.succeed`: the `warnings` (when present) are mapped effectfully and the
973
+ * `success` value is carried through unchanged.
974
+ *
975
+ * @example
976
+ * ```ts
977
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
978
+ * import { Effect } from "effect"
979
+ *
980
+ * const shout = WarnResult.mapWarningsEffect((warnings: string) =>
981
+ * Effect.succeed(warnings.toUpperCase())
982
+ * )
983
+ *
984
+ * assert.deepStrictEqual(
985
+ * Effect.runSync(
986
+ * shout(WarnResult.SuccessWithWarnings({ warnings: "w", success: 1 }))
987
+ * ),
988
+ * WarnResult.SuccessWithWarnings({ warnings: "W", success: 1 })
989
+ * )
990
+ * ```
991
+ *
992
+ * @category sequencing
993
+ * @since 0.0.0
994
+ */
995
+ export declare const mapWarningsEffect: <W1, W2, EW, RW>(mapWarnings: (warnings: W1) => Effect.Effect<W2, EW, RW>) => (<A>(warnResult: WarnResult<W1, A>) => Effect.Effect<WarnResult<W2, A>, EW, RW>);
996
+ /**
997
+ * Effectful `flatMapWarnings`: chains the `warnings` of a `WarnResult` into an
998
+ * `Effect` that yields a new `WarnResult`, flattening the result.
999
+ *
1000
+ * When `warnings` are present they are passed to `mapWarnings`, whose effectful
1001
+ * `WarnResult` replaces the original; `SuccessOnly` is lifted unchanged via
1002
+ * `Effect.succeed`. Use it to sequence warnings-driven effectful computations that
1003
+ * produce a `WarnResult`.
1004
+ *
1005
+ * @example
1006
+ * ```ts
1007
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
1008
+ * import { Effect } from "effect"
1009
+ *
1010
+ * const chain = WarnResult.flatMapWarningsEffect((warnings: string) =>
1011
+ * Effect.succeed(WarnResult.WarningsOnly({ warnings: warnings.toUpperCase() }))
1012
+ * )
1013
+ *
1014
+ * assert.deepStrictEqual(
1015
+ * Effect.runSync(chain(WarnResult.WarningsOnly({ warnings: "w" }))),
1016
+ * WarnResult.WarningsOnly({ warnings: "W" })
1017
+ * )
1018
+ * assert.deepStrictEqual(
1019
+ * Effect.runSync(chain(WarnResult.SuccessOnly({ success: 1 }))),
1020
+ * WarnResult.SuccessOnly({ success: 1 })
1021
+ * )
1022
+ * ```
1023
+ *
1024
+ * @category sequencing
1025
+ * @since 0.0.0
1026
+ */
1027
+ export declare const flatMapWarningsEffect: <W1, W2, A2, EW, RW>(mapWarnings: (warnings: W1) => Effect.Effect<WarnResult<W2, A2>, EW, RW>) => (<A1>(warnResult: WarnResult<W1, A1>) => Effect.Effect<WarnResult<W2, A1 | A2>, EW, RW>);
1028
+ /**
1029
+ * Transforms the `success` value of a `WarnResult`, leaving any `warnings`
1030
+ * untouched.
1031
+ *
1032
+ * The mirror of `mapWarnings`: `SuccessOnly` and `SuccessWithWarnings` have their
1033
+ * `success` value mapped, while `WarningsOnly` passes through unchanged.
1034
+ *
1035
+ * @example
1036
+ * ```ts
1037
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
1038
+ *
1039
+ * const inc = WarnResult.mapSuccess((success: number) => success + 1)
1040
+ *
1041
+ * assert.deepStrictEqual(
1042
+ * inc(WarnResult.SuccessWithWarnings({ warnings: "w", success: 1 })),
1043
+ * WarnResult.SuccessWithWarnings({ warnings: "w", success: 2 })
1044
+ * )
1045
+ * assert.deepStrictEqual(
1046
+ * inc(WarnResult.WarningsOnly({ warnings: "w" })),
1047
+ * WarnResult.WarningsOnly({ warnings: "w" })
1048
+ * )
1049
+ * ```
1050
+ *
1051
+ * @category mapping
1052
+ * @since 0.0.0
1053
+ */
1054
+ export declare const mapSuccess: <A1, A2>(mapSuccess: (success: A1) => A2) => (<W>(warnResult: WarnResult<W, A1>) => WarnResult<W, A2>);
1055
+ /**
1056
+ * Chains the `success` value of a `WarnResult` into a new `WarnResult`, flattening
1057
+ * the result.
1058
+ *
1059
+ * The mirror of `flatMapWarnings`: whenever a `success` value is present
1060
+ * (`SuccessOnly` or `SuccessWithWarnings`) it is passed to `mapSuccess`, whose
1061
+ * returned `WarnResult` replaces the original; `WarningsOnly` passes through
1062
+ * unchanged.
1063
+ *
1064
+ * @example
1065
+ * ```ts
1066
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
1067
+ *
1068
+ * const chain = WarnResult.flatMapSuccess((success: number) =>
1069
+ * WarnResult.SuccessOnly({ success: success + 1 })
1070
+ * )
1071
+ *
1072
+ * assert.deepStrictEqual(
1073
+ * chain(WarnResult.SuccessOnly({ success: 1 })),
1074
+ * WarnResult.SuccessOnly({ success: 2 })
1075
+ * )
1076
+ * assert.deepStrictEqual(
1077
+ * chain(WarnResult.WarningsOnly({ warnings: "w" })),
1078
+ * WarnResult.WarningsOnly({ warnings: "w" })
1079
+ * )
1080
+ * ```
1081
+ *
1082
+ * @category sequencing
1083
+ * @since 0.0.0
1084
+ */
1085
+ export declare const flatMapSuccess: <W2, A1, A2>(mapSuccess: (success: A1) => WarnResult<W2, A2>) => (<W1>(warnResult: WarnResult<W1, A1>) => WarnResult<W1 | W2, A2>);
1086
+ /**
1087
+ * Effectful `mapSuccess`: transforms the `success` value of a `WarnResult` through
1088
+ * an `Effect`, leaving any `warnings` untouched.
1089
+ *
1090
+ * The mirror of `mapWarningsEffect`: the `success` value (when present) is mapped
1091
+ * effectfully and the `warnings` are carried through unchanged via
1092
+ * `Effect.succeed`.
1093
+ *
1094
+ * @example
1095
+ * ```ts
1096
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
1097
+ * import { Effect } from "effect"
1098
+ *
1099
+ * const inc = WarnResult.mapSuccessEffect((success: number) =>
1100
+ * Effect.succeed(success + 1)
1101
+ * )
1102
+ *
1103
+ * assert.deepStrictEqual(
1104
+ * Effect.runSync(
1105
+ * inc(WarnResult.SuccessWithWarnings({ warnings: "w", success: 1 }))
1106
+ * ),
1107
+ * WarnResult.SuccessWithWarnings({ warnings: "w", success: 2 })
1108
+ * )
1109
+ * ```
1110
+ *
1111
+ * @category sequencing
1112
+ * @since 0.0.0
1113
+ */
1114
+ export declare const mapSuccessEffect: <A1, A2, EA, RA>(mapSuccess: (success: A1) => Effect.Effect<A2, EA, RA>) => (<W>(warnResult: WarnResult<W, A1>) => Effect.Effect<WarnResult<W, A2>, EA, RA>);
1115
+ /**
1116
+ * Effectful `flatMapSuccess`: chains the `success` value of a `WarnResult` into an
1117
+ * `Effect` that yields a new `WarnResult`, flattening the result.
1118
+ *
1119
+ * The mirror of `flatMapWarningsEffect`: when a `success` value is present it is
1120
+ * passed to `mapSuccess`, whose effectful `WarnResult` replaces the original;
1121
+ * `WarningsOnly` is lifted unchanged via `Effect.succeed`.
1122
+ *
1123
+ * @example
1124
+ * ```ts
1125
+ * import { WarnResult } from "@nunofyobiz/effect-extras"
1126
+ * import { Effect } from "effect"
1127
+ *
1128
+ * const chain = WarnResult.flatMapSuccessEffect((success: number) =>
1129
+ * Effect.succeed(WarnResult.SuccessOnly({ success: success + 1 }))
1130
+ * )
1131
+ *
1132
+ * assert.deepStrictEqual(
1133
+ * Effect.runSync(chain(WarnResult.SuccessOnly({ success: 1 }))),
1134
+ * WarnResult.SuccessOnly({ success: 2 })
1135
+ * )
1136
+ * assert.deepStrictEqual(
1137
+ * Effect.runSync(chain(WarnResult.WarningsOnly({ warnings: "w" }))),
1138
+ * WarnResult.WarningsOnly({ warnings: "w" })
1139
+ * )
1140
+ * ```
1141
+ *
1142
+ * @category sequencing
1143
+ * @since 0.0.0
1144
+ */
1145
+ export declare const flatMapSuccessEffect: <W2, A1, A2, EA, RA>(mapSuccess: (success: A1) => Effect.Effect<WarnResult<W2, A2>, EA, RA>) => (<W1>(warnResult: WarnResult<W1, A1>) => Effect.Effect<WarnResult<W1 | W2, A2>, EA, RA>);
1146
+ //# sourceMappingURL=WarnResult.d.ts.map