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