@carbonteq/fp 0.10.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -3
- package/dist/errors.cjs +1 -3
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts +2 -5
- package/dist/errors.d.cts.map +1 -1
- package/dist/errors.d.mts +2 -5
- package/dist/errors.d.mts.map +1 -1
- package/dist/errors.mjs +1 -2
- package/dist/errors.mjs.map +1 -1
- package/dist/flow-experimental.cjs +197 -151
- package/dist/flow-experimental.cjs.map +1 -1
- package/dist/flow-experimental.d.cts +11 -11
- package/dist/flow-experimental.d.cts.map +1 -1
- package/dist/flow-experimental.d.mts +11 -11
- package/dist/flow-experimental.d.mts.map +1 -1
- package/dist/flow-experimental.mjs +196 -150
- package/dist/flow-experimental.mjs.map +1 -1
- package/dist/flow.cjs +194 -150
- package/dist/flow.cjs.map +1 -1
- package/dist/flow.d.cts +8 -10
- package/dist/flow.d.cts.map +1 -1
- package/dist/flow.d.mts +8 -10
- package/dist/flow.d.mts.map +1 -1
- package/dist/flow.mjs +193 -149
- package/dist/flow.mjs.map +1 -1
- package/dist/index.cjs +10 -10
- package/dist/index.d.cts +7 -7
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +7 -7
- package/dist/match.cjs +100 -9
- package/dist/match.cjs.map +1 -1
- package/dist/match.d.cts +14 -21
- package/dist/match.d.cts.map +1 -1
- package/dist/match.d.mts +14 -21
- package/dist/match.d.mts.map +1 -1
- package/dist/match.mjs +100 -8
- package/dist/match.mjs.map +1 -1
- package/dist/option-experimental.cjs +101 -57
- package/dist/option-experimental.cjs.map +1 -1
- package/dist/option-experimental.d.cts +7 -10
- package/dist/option-experimental.d.cts.map +1 -1
- package/dist/option-experimental.d.mts +7 -10
- package/dist/option-experimental.d.mts.map +1 -1
- package/dist/option-experimental.mjs +100 -56
- package/dist/option-experimental.mjs.map +1 -1
- package/dist/option.cjs +170 -118
- package/dist/option.cjs.map +1 -1
- package/dist/option.d.cts +27 -19
- package/dist/option.d.cts.map +1 -1
- package/dist/option.d.mts +27 -19
- package/dist/option.d.mts.map +1 -1
- package/dist/option.mjs +169 -117
- package/dist/option.mjs.map +1 -1
- package/dist/result-experimental.cjs +197 -117
- package/dist/result-experimental.cjs.map +1 -1
- package/dist/result-experimental.d.cts +26 -26
- package/dist/result-experimental.d.cts.map +1 -1
- package/dist/result-experimental.d.mts +26 -26
- package/dist/result-experimental.d.mts.map +1 -1
- package/dist/result-experimental.mjs +195 -115
- package/dist/result-experimental.mjs.map +1 -1
- package/dist/result.cjs +245 -173
- package/dist/result.cjs.map +1 -1
- package/dist/result.d.cts +26 -22
- package/dist/result.d.cts.map +1 -1
- package/dist/result.d.mts +26 -22
- package/dist/result.d.mts.map +1 -1
- package/dist/result.mjs +243 -171
- package/dist/result.mjs.map +1 -1
- package/dist/tuple.cjs +3 -5
- package/dist/tuple.cjs.map +1 -1
- package/dist/tuple.d.cts +6 -8
- package/dist/tuple.d.cts.map +1 -1
- package/dist/tuple.d.mts +6 -8
- package/dist/tuple.d.mts.map +1 -1
- package/dist/tuple.mjs +3 -4
- package/dist/tuple.mjs.map +1 -1
- package/dist/unit.cjs +1 -3
- package/dist/unit.cjs.map +1 -1
- package/dist/unit.d.cts +2 -5
- package/dist/unit.d.cts.map +1 -1
- package/dist/unit.d.mts +2 -5
- package/dist/unit.d.mts.map +1 -1
- package/dist/unit.mjs +1 -2
- package/dist/unit.mjs.map +1 -1
- package/dist/utils.cjs +35 -3
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +7 -6
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts +7 -6
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +34 -3
- package/dist/utils.mjs.map +1 -1
- package/examples/README.md +14 -0
- package/examples/flow/04-complex-backend.ts +7 -4
- package/examples/flow-experimental/04-complex-backend.ts +7 -4
- package/examples/match/01-stable-match.ts +7 -0
- package/examples/match-experimental/01-experimental-match.ts +7 -0
- package/package.json +22 -31
package/dist/option.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
2
|
+
const require_result = require("./result.cjs");
|
|
3
|
+
const require_unit = require("./unit.cjs");
|
|
4
|
+
const require_utils = require("./utils.cjs");
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
// src/option.ts
|
|
7
7
|
var UnwrappedNone = class extends Error {
|
|
8
8
|
name = "UnwrapError";
|
|
9
9
|
constructor() {
|
|
@@ -18,6 +18,7 @@ const NONE_VAL = Symbol("Option::None");
|
|
|
18
18
|
* @internal
|
|
19
19
|
*/
|
|
20
20
|
var OptionYieldWrap = class {
|
|
21
|
+
option;
|
|
21
22
|
constructor(option) {
|
|
22
23
|
this.option = option;
|
|
23
24
|
}
|
|
@@ -120,10 +121,11 @@ var Option = class Option {
|
|
|
120
121
|
*/
|
|
121
122
|
static fromPromise(o) {
|
|
122
123
|
const ctx = { promiseNoneSlot: false };
|
|
123
|
-
|
|
124
|
+
const p = new Promise((resolve, reject) => o.then((innerOpt) => {
|
|
124
125
|
if (innerOpt.isNone()) ctx.promiseNoneSlot = true;
|
|
125
126
|
resolve(innerOpt.#val);
|
|
126
|
-
}, reject))
|
|
127
|
+
}, reject));
|
|
128
|
+
return new Option(p, ctx, "Some");
|
|
127
129
|
}
|
|
128
130
|
/**
|
|
129
131
|
* Combines multiple Options into a single Option of an array.
|
|
@@ -145,34 +147,35 @@ var Option = class Option {
|
|
|
145
147
|
/**
|
|
146
148
|
* Returns the first Some in the list, or None if all are None.
|
|
147
149
|
*
|
|
148
|
-
*
|
|
150
|
+
* Awaits candidates in input order, without waiting for the suffix after success.
|
|
149
151
|
*
|
|
150
152
|
* @template T - Value type
|
|
151
153
|
* @param options - Options to search
|
|
152
154
|
* @returns The first Some found, otherwise None
|
|
153
155
|
*/
|
|
154
156
|
static any(...options) {
|
|
155
|
-
|
|
156
|
-
for (const opt of options)
|
|
157
|
+
let hasPending = false;
|
|
158
|
+
for (const opt of options) {
|
|
159
|
+
if (!opt.isSome()) continue;
|
|
157
160
|
if (require_utils.isPromiseLike(opt.#val)) {
|
|
158
|
-
|
|
159
|
-
|
|
161
|
+
hasPending = true;
|
|
162
|
+
break;
|
|
160
163
|
}
|
|
161
164
|
return opt;
|
|
162
165
|
}
|
|
163
|
-
if (
|
|
166
|
+
if (!hasPending) return Option.None;
|
|
167
|
+
for (const opt of options) if (require_utils.isPromiseLike(opt.#val)) Promise.resolve(opt.#val).then(void 0, () => {});
|
|
164
168
|
const ctx = { promiseNoneSlot: false };
|
|
165
|
-
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
val
|
|
170
|
-
}
|
|
171
|
-
})).then((settled) => {
|
|
172
|
-
for (const item of settled) if (!item.isNone) return item.val;
|
|
169
|
+
const p = (async () => {
|
|
170
|
+
for (const opt of options) {
|
|
171
|
+
if (!opt.isSome()) continue;
|
|
172
|
+
const val = await opt.#val;
|
|
173
|
+
if (!opt.#ctx.promiseNoneSlot && val !== NONE_VAL) return val;
|
|
174
|
+
}
|
|
173
175
|
ctx.promiseNoneSlot = true;
|
|
174
176
|
return NONE_VAL;
|
|
175
|
-
})
|
|
177
|
+
})();
|
|
178
|
+
return new Option(p, ctx, "Some");
|
|
176
179
|
}
|
|
177
180
|
/**
|
|
178
181
|
* Type guard that narrows to Some.
|
|
@@ -185,7 +188,7 @@ var Option = class Option {
|
|
|
185
188
|
/**
|
|
186
189
|
* Type guard that narrows to None.
|
|
187
190
|
*
|
|
188
|
-
* Includes async None tracking
|
|
191
|
+
* Includes async None tracking while preserving the stored payload type.
|
|
189
192
|
*
|
|
190
193
|
* @returns true if this Option is None
|
|
191
194
|
*/
|
|
@@ -212,25 +215,21 @@ var Option = class Option {
|
|
|
212
215
|
}
|
|
213
216
|
return curr;
|
|
214
217
|
}
|
|
215
|
-
/**
|
|
216
|
-
* Returns the contained value or the provided default.
|
|
217
|
-
*
|
|
218
|
-
* @param defaultValue - Value to use when None
|
|
219
|
-
* @returns The contained value or default
|
|
220
|
-
*/
|
|
221
218
|
unwrapOr(defaultValue) {
|
|
222
|
-
|
|
223
|
-
|
|
219
|
+
const curr = this.#val;
|
|
220
|
+
if (require_utils.isPromiseLike(curr)) {
|
|
221
|
+
const ctx = this.#ctx;
|
|
222
|
+
return curr.then((value) => value === NONE_VAL || ctx.promiseNoneSlot ? defaultValue : value);
|
|
223
|
+
}
|
|
224
|
+
return this.isNone() ? defaultValue : curr;
|
|
224
225
|
}
|
|
225
|
-
/**
|
|
226
|
-
* Returns the contained value or computes a default lazily.
|
|
227
|
-
*
|
|
228
|
-
* @param fn - Default factory invoked only when None
|
|
229
|
-
* @returns The contained value or computed default
|
|
230
|
-
*/
|
|
231
226
|
unwrapOrElse(fn) {
|
|
232
|
-
|
|
233
|
-
|
|
227
|
+
const curr = this.#val;
|
|
228
|
+
if (require_utils.isPromiseLike(curr)) {
|
|
229
|
+
const ctx = this.#ctx;
|
|
230
|
+
return curr.then((value) => value === NONE_VAL || ctx.promiseNoneSlot ? fn() : value);
|
|
231
|
+
}
|
|
232
|
+
return this.isNone() ? fn() : curr;
|
|
234
233
|
}
|
|
235
234
|
safeUnwrap() {
|
|
236
235
|
if (this.isNone()) return null;
|
|
@@ -258,7 +257,8 @@ var Option = class Option {
|
|
|
258
257
|
if (require_utils.isPromiseLike(curr)) {
|
|
259
258
|
const p = curr;
|
|
260
259
|
const newCtx = { promiseNoneSlot: false };
|
|
261
|
-
|
|
260
|
+
const safetlyMapped = Option.safeMap(p, mapper, newCtx);
|
|
261
|
+
return new Option(safetlyMapped, newCtx, "Some");
|
|
262
262
|
}
|
|
263
263
|
const transformed = mapper(curr);
|
|
264
264
|
if (require_utils.isPromiseLike(transformed)) return new Option(transformed, { promiseNoneSlot: false }, "Some");
|
|
@@ -302,25 +302,20 @@ var Option = class Option {
|
|
|
302
302
|
if (require_utils.isPromiseLike(curr)) {
|
|
303
303
|
const p = curr;
|
|
304
304
|
const newCtx = { promiseNoneSlot: false };
|
|
305
|
-
const
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
resolve(NONE_VAL);
|
|
320
|
-
} else resolve(r.#val);
|
|
321
|
-
}
|
|
322
|
-
}, reject);
|
|
323
|
-
}), newCtx, "Some");
|
|
305
|
+
const newP = p.then(async (innerVal) => {
|
|
306
|
+
if (innerVal === NONE_VAL) {
|
|
307
|
+
newCtx.promiseNoneSlot = true;
|
|
308
|
+
return NONE_VAL;
|
|
309
|
+
}
|
|
310
|
+
const mapped = await mapper(innerVal);
|
|
311
|
+
const value = await mapped.#val;
|
|
312
|
+
if (mapped.isNone() || value === NONE_VAL) {
|
|
313
|
+
newCtx.promiseNoneSlot = true;
|
|
314
|
+
return NONE_VAL;
|
|
315
|
+
}
|
|
316
|
+
return value;
|
|
317
|
+
});
|
|
318
|
+
return new Option(newP, newCtx, "Some");
|
|
324
319
|
}
|
|
325
320
|
const mapped = mapper(curr);
|
|
326
321
|
if (require_utils.isPromiseLike(mapped)) return Option.fromPromise(mapped);
|
|
@@ -332,7 +327,7 @@ var Option = class Option {
|
|
|
332
327
|
if (require_utils.isPromiseLike(curr)) {
|
|
333
328
|
const p = curr;
|
|
334
329
|
const newCtx = { promiseNoneSlot: false };
|
|
335
|
-
|
|
330
|
+
const next = p.then(async (v) => {
|
|
336
331
|
if (v === NONE_VAL) {
|
|
337
332
|
newCtx.promiseNoneSlot = true;
|
|
338
333
|
return NONE_VAL;
|
|
@@ -342,16 +337,18 @@ var Option = class Option {
|
|
|
342
337
|
return NONE_VAL;
|
|
343
338
|
}
|
|
344
339
|
return v;
|
|
345
|
-
})
|
|
340
|
+
});
|
|
341
|
+
return new Option(next, newCtx, "Some");
|
|
346
342
|
}
|
|
347
343
|
const result = pred(curr);
|
|
348
344
|
if (require_utils.isPromiseLike(result)) {
|
|
349
345
|
const newCtx = { promiseNoneSlot: false };
|
|
350
|
-
|
|
346
|
+
const p = result.then((passed) => {
|
|
351
347
|
if (passed) return curr;
|
|
352
348
|
newCtx.promiseNoneSlot = true;
|
|
353
349
|
return NONE_VAL;
|
|
354
|
-
})
|
|
350
|
+
});
|
|
351
|
+
return new Option(p, newCtx, "Some");
|
|
355
352
|
}
|
|
356
353
|
return result ? this : Option.None;
|
|
357
354
|
}
|
|
@@ -361,17 +358,21 @@ var Option = class Option {
|
|
|
361
358
|
if (require_utils.isPromiseLike(curr)) {
|
|
362
359
|
const val = curr;
|
|
363
360
|
const newCtx = { promiseNoneSlot: false };
|
|
364
|
-
|
|
361
|
+
const p = val.then(async (v) => {
|
|
365
362
|
if (v === NONE_VAL) {
|
|
366
363
|
newCtx.promiseNoneSlot = true;
|
|
367
364
|
return NONE_VAL;
|
|
368
365
|
}
|
|
369
366
|
return [v, await fn(v)];
|
|
370
|
-
})
|
|
367
|
+
});
|
|
368
|
+
return new Option(p, newCtx, "Some");
|
|
371
369
|
}
|
|
372
370
|
const value = curr;
|
|
373
371
|
const u = fn(value);
|
|
374
|
-
if (require_utils.isPromiseLike(u))
|
|
372
|
+
if (require_utils.isPromiseLike(u)) {
|
|
373
|
+
const p = u.then((uu) => [value, uu]);
|
|
374
|
+
return new Option(p, { promiseNoneSlot: false }, "Some");
|
|
375
|
+
}
|
|
375
376
|
return new Option([value, u], { promiseNoneSlot: false }, "Some");
|
|
376
377
|
}
|
|
377
378
|
flatZip(fn) {
|
|
@@ -380,7 +381,7 @@ var Option = class Option {
|
|
|
380
381
|
if (require_utils.isPromiseLike(curr)) {
|
|
381
382
|
const val = curr;
|
|
382
383
|
const newCtx = { promiseNoneSlot: false };
|
|
383
|
-
|
|
384
|
+
const p = val.then(async (v) => {
|
|
384
385
|
if (v === NONE_VAL) {
|
|
385
386
|
newCtx.promiseNoneSlot = true;
|
|
386
387
|
return NONE_VAL;
|
|
@@ -391,19 +392,21 @@ var Option = class Option {
|
|
|
391
392
|
return NONE_VAL;
|
|
392
393
|
}
|
|
393
394
|
return [v, next.#val];
|
|
394
|
-
})
|
|
395
|
+
});
|
|
396
|
+
return new Option(p, newCtx, "Some");
|
|
395
397
|
}
|
|
396
398
|
const c = curr;
|
|
397
399
|
const u = fn(c);
|
|
398
400
|
if (require_utils.isPromiseLike(u)) {
|
|
399
401
|
const newCtx = { promiseNoneSlot: false };
|
|
400
|
-
|
|
402
|
+
const p = u.then((uu) => {
|
|
401
403
|
if (uu.isNone()) {
|
|
402
404
|
newCtx.promiseNoneSlot = true;
|
|
403
405
|
return NONE_VAL;
|
|
404
406
|
}
|
|
405
407
|
return [c, uu.#val];
|
|
406
|
-
})
|
|
408
|
+
});
|
|
409
|
+
return new Option(p, newCtx, "Some");
|
|
407
410
|
}
|
|
408
411
|
return u.map((inner) => [c, inner]);
|
|
409
412
|
}
|
|
@@ -422,12 +425,14 @@ var Option = class Option {
|
|
|
422
425
|
}
|
|
423
426
|
/**
|
|
424
427
|
* Converts this Option to a Result, using the provided error for None.
|
|
428
|
+
* Promise-backed Options preserve settled absence and propagate rejections.
|
|
425
429
|
*
|
|
426
430
|
* @template E - Error type
|
|
427
431
|
* @param error - Error value for None
|
|
428
432
|
* @returns Ok with value when Some, otherwise Err with error
|
|
429
433
|
*/
|
|
430
434
|
toResult(error) {
|
|
435
|
+
if (require_utils.isPromiseLike(this.#val)) return require_result.Result.fromPromise(this.toPromise().then((option) => option.isNone() ? require_result.Result.Err(error) : require_result.Result.Ok(option.unwrap())));
|
|
431
436
|
if (this.isNone()) return require_result.Result.Err(error);
|
|
432
437
|
return require_result.Result.Ok(this.#val);
|
|
433
438
|
}
|
|
@@ -569,19 +574,29 @@ var Option = class Option {
|
|
|
569
574
|
const iterator = genFn();
|
|
570
575
|
let nextArg;
|
|
571
576
|
let currentResult;
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
577
|
+
let naturalCompleted = false;
|
|
578
|
+
try {
|
|
579
|
+
while (true) {
|
|
580
|
+
const next = iterator.next(nextArg);
|
|
581
|
+
if (next.done) {
|
|
582
|
+
naturalCompleted = true;
|
|
583
|
+
currentResult = Option.Some(next.value);
|
|
584
|
+
break;
|
|
585
|
+
}
|
|
586
|
+
let yielded = next.value;
|
|
587
|
+
if (require_utils.isCapturedTrace(yielded)) yielded = yielded.value;
|
|
588
|
+
if (yielded.isNone()) {
|
|
589
|
+
currentResult = Option.None;
|
|
590
|
+
break;
|
|
591
|
+
}
|
|
592
|
+
nextArg = yielded.unwrap();
|
|
583
593
|
}
|
|
584
|
-
|
|
594
|
+
} finally {
|
|
595
|
+
if (!naturalCompleted) require_utils.closeGenerator(iterator, (yielded) => {
|
|
596
|
+
if (require_utils.isCapturedTrace(yielded)) yielded = yielded.value;
|
|
597
|
+
const effect = yielded;
|
|
598
|
+
return effect.isNone() ? void 0 : effect.unwrap();
|
|
599
|
+
});
|
|
585
600
|
}
|
|
586
601
|
return currentResult;
|
|
587
602
|
}
|
|
@@ -634,19 +649,30 @@ var Option = class Option {
|
|
|
634
649
|
const iterator = genFn(adapter);
|
|
635
650
|
let nextArg;
|
|
636
651
|
let currentResult;
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
652
|
+
let naturalCompleted = false;
|
|
653
|
+
try {
|
|
654
|
+
while (true) {
|
|
655
|
+
const next = iterator.next(nextArg);
|
|
656
|
+
if (next.done) {
|
|
657
|
+
naturalCompleted = true;
|
|
658
|
+
currentResult = Option.Some(next.value);
|
|
659
|
+
break;
|
|
660
|
+
}
|
|
661
|
+
let option = next.value.option;
|
|
662
|
+
if (require_utils.isCapturedTrace(option)) option = option.value;
|
|
663
|
+
if (option.isNone()) {
|
|
664
|
+
currentResult = Option.None;
|
|
665
|
+
break;
|
|
666
|
+
}
|
|
667
|
+
nextArg = option.unwrap();
|
|
648
668
|
}
|
|
649
|
-
|
|
669
|
+
} finally {
|
|
670
|
+
if (!naturalCompleted) require_utils.closeGenerator(iterator, (yielded) => {
|
|
671
|
+
if (require_utils.isCapturedTrace(yielded)) yielded = yielded.value;
|
|
672
|
+
let effect = yielded.option;
|
|
673
|
+
if (require_utils.isCapturedTrace(effect)) effect = effect.value;
|
|
674
|
+
return effect.isNone() ? void 0 : effect.unwrap();
|
|
675
|
+
});
|
|
650
676
|
}
|
|
651
677
|
return currentResult;
|
|
652
678
|
}
|
|
@@ -704,6 +730,7 @@ var Option = class Option {
|
|
|
704
730
|
* }
|
|
705
731
|
* ```
|
|
706
732
|
*
|
|
733
|
+
* Settles promise-backed Options before checking for None; raw rejections propagate.
|
|
707
734
|
* @see {@link asyncGenAdapter} for better type inference and cleaner syntax
|
|
708
735
|
* @see {@link gen} for synchronous operations
|
|
709
736
|
*/
|
|
@@ -711,19 +738,31 @@ var Option = class Option {
|
|
|
711
738
|
const iterator = genFn();
|
|
712
739
|
let nextArg;
|
|
713
740
|
let currentResult;
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
741
|
+
let naturalCompleted = false;
|
|
742
|
+
try {
|
|
743
|
+
while (true) {
|
|
744
|
+
const next = await iterator.next(nextArg);
|
|
745
|
+
if (next.done) {
|
|
746
|
+
naturalCompleted = true;
|
|
747
|
+
currentResult = Option.Some(next.value);
|
|
748
|
+
break;
|
|
749
|
+
}
|
|
750
|
+
let option = next.value;
|
|
751
|
+
if (require_utils.isCapturedTrace(option)) option = option.value;
|
|
752
|
+
option = await option.toPromise();
|
|
753
|
+
if (option.isNone()) {
|
|
754
|
+
currentResult = Option.None;
|
|
755
|
+
break;
|
|
756
|
+
}
|
|
757
|
+
nextArg = await option.unwrap();
|
|
725
758
|
}
|
|
726
|
-
|
|
759
|
+
} finally {
|
|
760
|
+
if (!naturalCompleted) await require_utils.closeAsyncGenerator(iterator, async (yielded) => {
|
|
761
|
+
if (require_utils.isCapturedTrace(yielded)) yielded = yielded.value;
|
|
762
|
+
let effect = yielded;
|
|
763
|
+
effect = await effect.toPromise();
|
|
764
|
+
return effect.isNone() ? void 0 : effect.unwrap();
|
|
765
|
+
});
|
|
727
766
|
}
|
|
728
767
|
return currentResult;
|
|
729
768
|
}
|
|
@@ -732,6 +771,7 @@ var Option = class Option {
|
|
|
732
771
|
*
|
|
733
772
|
* The `$` adapter handles both sync `Option<T>` and async `Promise<Option<T>>`,
|
|
734
773
|
* automatically awaiting promises. This provides cleaner syntax for mixed sync/async workflows.
|
|
774
|
+
* Settles promise-backed Options before checking for None; raw rejections propagate.
|
|
735
775
|
*
|
|
736
776
|
* Short-circuits on first `None`, returning singleton `None`. Uses async iteration
|
|
737
777
|
* instead of recursion to avoid stack overflow on deep chains.
|
|
@@ -783,25 +823,37 @@ var Option = class Option {
|
|
|
783
823
|
const iterator = genFn(adapter);
|
|
784
824
|
let nextArg;
|
|
785
825
|
let currentResult;
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
826
|
+
let naturalCompleted = false;
|
|
827
|
+
try {
|
|
828
|
+
while (true) {
|
|
829
|
+
const next = await iterator.next(nextArg);
|
|
830
|
+
if (next.done) {
|
|
831
|
+
naturalCompleted = true;
|
|
832
|
+
currentResult = Option.Some(next.value);
|
|
833
|
+
break;
|
|
834
|
+
}
|
|
835
|
+
let option = await next.value.option;
|
|
836
|
+
if (require_utils.isCapturedTrace(option)) option = option.value;
|
|
837
|
+
option = await option.toPromise();
|
|
838
|
+
if (option.isNone()) {
|
|
839
|
+
currentResult = Option.None;
|
|
840
|
+
break;
|
|
841
|
+
}
|
|
842
|
+
nextArg = await option.unwrap();
|
|
797
843
|
}
|
|
798
|
-
|
|
844
|
+
} finally {
|
|
845
|
+
if (!naturalCompleted) await require_utils.closeAsyncGenerator(iterator, async (yielded) => {
|
|
846
|
+
if (require_utils.isCapturedTrace(yielded)) yielded = yielded.value;
|
|
847
|
+
let effect = await yielded.option;
|
|
848
|
+
if (require_utils.isCapturedTrace(effect)) effect = effect.value;
|
|
849
|
+
effect = await effect.toPromise();
|
|
850
|
+
return effect.isNone() ? void 0 : effect.unwrap();
|
|
851
|
+
});
|
|
799
852
|
}
|
|
800
853
|
return currentResult;
|
|
801
854
|
}
|
|
802
855
|
};
|
|
803
856
|
|
|
804
|
-
//#endregion
|
|
805
857
|
exports.Option = Option;
|
|
806
858
|
exports.UnwrappedNone = UnwrappedNone;
|
|
807
859
|
//# sourceMappingURL=option.cjs.map
|