@fncts/io 0.0.6 → 0.0.7

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 (71) hide show
  1. package/FiberRefs/join.d.ts +1 -1
  2. package/IO/api/interrupt.d.ts +2 -1
  3. package/IO/api/sequenceT.d.ts +1 -1
  4. package/IO/api/withEarlyRelease.d.ts +10 -0
  5. package/IO/api/zipC.d.ts +7 -0
  6. package/IO/api.d.ts +7 -0
  7. package/IO.d.ts +1 -1
  8. package/Stream/api.d.ts +5 -0
  9. package/_cjs/Fiber/FiberContext.cjs +14 -14
  10. package/_cjs/Fiber/FiberContext.cjs.map +1 -1
  11. package/_cjs/Fiber/api/zipWith.cjs +1 -1
  12. package/_cjs/FiberRefs/join.cjs +58 -44
  13. package/_cjs/FiberRefs/join.cjs.map +1 -1
  14. package/_cjs/Hub/internal.cjs +2 -2
  15. package/_cjs/Hub/internal.cjs.map +1 -1
  16. package/_cjs/IO/api/interrupt.cjs.map +1 -1
  17. package/_cjs/IO/api/withEarlyRelease.cjs +31 -0
  18. package/_cjs/IO/api/withEarlyRelease.cjs.map +1 -0
  19. package/_cjs/IO/api/zipC.cjs +48 -4
  20. package/_cjs/IO/api/zipC.cjs.map +1 -1
  21. package/_cjs/IO/api.cjs +12 -9
  22. package/_cjs/IO/api.cjs.map +1 -1
  23. package/_cjs/IO.cjs +13 -13
  24. package/_cjs/Layer/MemoMap.cjs +1 -1
  25. package/_cjs/Queue/api/zipWithIO.cjs +5 -7
  26. package/_cjs/Queue/api/zipWithIO.cjs.map +1 -1
  27. package/_cjs/Stream/api.cjs +15 -5
  28. package/_cjs/Stream/api.cjs.map +1 -1
  29. package/_cjs/internal/Hub.cjs +3 -4
  30. package/_cjs/internal/Hub.cjs.map +1 -1
  31. package/_mjs/Fiber/FiberContext.mjs +14 -14
  32. package/_mjs/Fiber/FiberContext.mjs.map +1 -1
  33. package/_mjs/Fiber/api/zipWith.mjs +1 -1
  34. package/_mjs/FiberRefs/join.mjs +56 -40
  35. package/_mjs/FiberRefs/join.mjs.map +1 -1
  36. package/_mjs/Hub/internal.mjs +2 -2
  37. package/_mjs/Hub/internal.mjs.map +1 -1
  38. package/_mjs/IO/api/interrupt.mjs.map +1 -1
  39. package/_mjs/IO/api/withEarlyRelease.mjs +16 -0
  40. package/_mjs/IO/api/withEarlyRelease.mjs.map +1 -0
  41. package/_mjs/IO/api/zipC.mjs +32 -3
  42. package/_mjs/IO/api/zipC.mjs.map +1 -1
  43. package/_mjs/IO/api.mjs +11 -10
  44. package/_mjs/IO/api.mjs.map +1 -1
  45. package/_mjs/IO.mjs +1 -1
  46. package/_mjs/IO.mjs.map +1 -1
  47. package/_mjs/Layer/MemoMap.mjs +1 -1
  48. package/_mjs/Queue/api/zipWithIO.mjs +5 -6
  49. package/_mjs/Queue/api/zipWithIO.mjs.map +1 -1
  50. package/_mjs/Stream/api.mjs +12 -4
  51. package/_mjs/Stream/api.mjs.map +1 -1
  52. package/_mjs/internal/Hub.mjs +3 -4
  53. package/_mjs/internal/Hub.mjs.map +1 -1
  54. package/_src/Fiber/FiberContext.ts +3 -3
  55. package/_src/FiberRefs/join.ts +42 -29
  56. package/_src/Hub/internal.ts +2 -2
  57. package/_src/IO/api/interrupt.ts +1 -1
  58. package/_src/IO/api/sequenceT.ts +1 -1
  59. package/_src/IO/api/withEarlyRelease.ts +13 -0
  60. package/_src/IO/api/zipC.ts +61 -0
  61. package/_src/IO/api.ts +9 -9
  62. package/_src/IO.ts +1 -1
  63. package/_src/Stream/api.ts +10 -0
  64. package/_src/internal/Hub.ts +5 -6
  65. package/package.json +2 -2
  66. package/IO/api/zipWithC.d.ts +0 -9
  67. package/_cjs/IO/api/zipWithC.cjs +0 -40
  68. package/_cjs/IO/api/zipWithC.cjs.map +0 -1
  69. package/_mjs/IO/api/zipWithC.mjs +0 -23
  70. package/_mjs/IO/api/zipWithC.mjs.map +0 -1
  71. package/_src/IO/api/zipWithC.ts +0 -41
@@ -1,4 +1,5 @@
1
1
  import { tuple } from "@fncts/base/data/function";
2
+ import { AtomicReference } from "@fncts/base/internal/AtomicReference";
2
3
 
3
4
  /**
4
5
  * @tsplus fluent fncts.io.IO zipC
@@ -6,3 +7,63 @@ import { tuple } from "@fncts/base/data/function";
6
7
  export function zipC_<R, E, A, R1, E1, B>(self: IO<R, E, A>, that: IO<R1, E1, B>): IO<R & R1, E | E1, readonly [A, B]> {
7
8
  return self.zipWithC(that, tuple);
8
9
  }
10
+
11
+ /**
12
+ * @tsplus fluent fncts.io.IO zipWithC
13
+ */
14
+ export function zipWithC_<R, E, A, R1, E1, B, C>(
15
+ self: IO<R, E, A>,
16
+ that: IO<R1, E1, B>,
17
+ f: (a: A, b: B) => C,
18
+ ): IO<R & R1, E | E1, C> {
19
+ return IO.descriptorWith((descriptor) =>
20
+ IO.uninterruptibleMask(({ restore }) => {
21
+ const future = Future.unsafeMake<void, C>(FiberId.none);
22
+ const ref = new AtomicReference<Maybe<Either<A, B>>>(Nothing());
23
+ return IO.transplant((graft) =>
24
+ graft(
25
+ restore(self).matchCauseIO(
26
+ (cause) => future.fail(undefined) > IO.failCauseNow(cause),
27
+ (a) =>
28
+ ref.getAndSet(Just(Either.left(a))).match(
29
+ () => IO.unit,
30
+ (value) =>
31
+ value.match(
32
+ () => IO.unit,
33
+ (b) => future.succeed(f(a, b)).asUnit,
34
+ ),
35
+ ),
36
+ ),
37
+ )
38
+ .forkDaemon.zip(
39
+ graft(
40
+ restore(that).matchCauseIO(
41
+ (cause) => future.fail(undefined) > IO.failCauseNow(cause),
42
+ (b) =>
43
+ ref.getAndSet(Just(Either.right(b))).match(
44
+ () => IO.unit,
45
+ (value) =>
46
+ value.match(
47
+ (a) => future.succeed(f(a, b)).asUnit,
48
+ () => IO.unit,
49
+ ),
50
+ ),
51
+ ),
52
+ ).forkDaemon,
53
+ )
54
+ .flatMap(([left, right]) =>
55
+ restore(future.await).matchCauseIO(
56
+ (cause) =>
57
+ left
58
+ .interruptAs(descriptor.id)
59
+ .zipC(right.interruptAs(descriptor.id))
60
+ .flatMap(([left, right]) =>
61
+ left.zipC(right).match(IO.failCauseNow, () => IO.failCauseNow(cause.stripFailures)),
62
+ ),
63
+ (c) => left.inheritRefs.zip(right.inheritRefs).as(c),
64
+ ),
65
+ ),
66
+ );
67
+ }),
68
+ );
69
+ }
package/_src/IO/api.ts CHANGED
@@ -92,15 +92,15 @@ export function asyncInterrupt<R, E, A>(
92
92
  return new Async(register, blockingOn, __tsplusTrace);
93
93
  }
94
94
 
95
- // /**
96
- // * Attempts to convert defects into a failure, throwing away all information
97
- // * about the cause of the failure.
98
- // *
99
- // * @tsplus fluent fncts.io.IO absorbWith
100
- // */
101
- // export function absorbWith_<R, E, A>(ma: IO<R, E, A>, f: (e: E) => unknown, __tsplusTrace?: string) {
102
- // return ma.sandbox.matchIO((cause) => IO.failNow(cause.squash(f)), IO.succeedNow)
103
- // }
95
+ /**
96
+ * Attempts to convert defects into a failure, throwing away all information
97
+ * about the cause of the failure.
98
+ *
99
+ * @tsplus fluent fncts.io.IO absorbWith
100
+ */
101
+ export function absorbWith_<R, E, A>(ma: IO<R, E, A>, f: (e: E) => unknown, __tsplusTrace?: string) {
102
+ return ma.sandbox.matchIO((cause) => IO.failNow(cause.squashWith(f)), IO.succeedNow)
103
+ }
104
104
 
105
105
  /**
106
106
  * @tsplus fluent fncts.io.IO apFirst
package/_src/IO.ts CHANGED
@@ -47,9 +47,9 @@ export * from "./IO/api/sleep.js";
47
47
  export * from "./IO/api/stateful.js";
48
48
  export * from "./IO/api/timeout.js";
49
49
  export * from "./IO/api/withChildren.js";
50
+ export * from "./IO/api/withEarlyRelease.js";
50
51
  export * from "./IO/api/withFinalizer.js";
51
52
  export * from "./IO/api/withFinalizerExit.js";
52
53
  export * from "./IO/api/withRuntimeConfig.js";
53
54
  export * from "./IO/api/zipC.js";
54
- export * from "./IO/api/zipWithC.js";
55
55
  // codegen:end
@@ -2931,6 +2931,16 @@ export function unwrapScoped<R0, E0, R, E, A>(
2931
2931
  return Stream.scoped(stream).flatten;
2932
2932
  }
2933
2933
 
2934
+ /**
2935
+ * @tsplus getter fncts.io.Stream zipWithIndex
2936
+ */
2937
+ export function zipWithIndex_<R, E, A>(
2938
+ self: Stream<R, E, A>,
2939
+ __tsPlusTrace?: string,
2940
+ ): Stream<R, E, readonly [A, number]> {
2941
+ return self.mapAccum(0, (index, a) => [index + 1, [a, index]]);
2942
+ }
2943
+
2934
2944
  /**
2935
2945
  * Zips the two streams so that when a value is emitted by either of the two
2936
2946
  * streams, it is combined with the latest value from the other stream to
@@ -633,7 +633,7 @@ class UnboundedHubSubscription<A> extends SubscriptionInternal<A> {
633
633
  } else {
634
634
  const a = this.subscriberHead.next!.value;
635
635
 
636
- if (a !== null) {
636
+ if (a != null) {
637
637
  polled = a;
638
638
  this.subscriberHead.subscribers -= 1;
639
639
 
@@ -655,13 +655,12 @@ class UnboundedHubSubscription<A> extends SubscriptionInternal<A> {
655
655
  }
656
656
 
657
657
  pollUpTo(n: number): Conc<A> {
658
- let builder = Conc.empty<A>();
659
- const default_ = null;
660
- let i = 0;
658
+ let builder = Conc.empty<A>();
659
+ let i = 0;
661
660
 
662
661
  while (i !== n) {
663
- const a = this.poll(default_ as unknown as A);
664
- if (a === default_) {
662
+ const a = this.poll(null as unknown as A);
663
+ if (a == null) {
665
664
  i = n;
666
665
  } else {
667
666
  builder = builder.append(a);
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@fncts/io",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "dependencies": {
5
- "@fncts/base": "0.0.6",
5
+ "@fncts/base": "0.0.7",
6
6
  "@fncts/typelevel": "0.0.6"
7
7
  },
8
8
  "exports": {
@@ -1,9 +0,0 @@
1
- import { IO } from "@fncts/io/IO/definition";
2
- import { FiberId } from "@fncts/base/data/FiberId";
3
- import { Exit } from "@fncts/base/data/Exit";
4
- import { Fiber } from "@fncts/io/Fiber/definition";
5
- /**
6
- * @tsplus fluent fncts.io.IO zipWithC
7
- * @tsplus location "@fncts/io/IO/api/zipWithC"
8
- */
9
- export declare function zipWithC_<R, E, A, R1, E1, B, C>(self: IO<R, E, A>, that: IO<R1, E1, B>, f: (a: A, b: B) => C): IO<R & R1, E | E1, C>;
@@ -1,40 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.zipWithC_ = zipWithC_;
7
-
8
- var tsplus_module_1 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/io/IO/api/core-scope"));
9
-
10
- var tsplus_module_2 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/io/IO/api"));
11
-
12
- var tsplus_module_3 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/base/data/Cause/api"));
13
-
14
- var tsplus_module_4 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/base/data/Exit/api"));
15
-
16
- var tsplus_module_5 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/io/Fiber/api/interruptAs"));
17
-
18
- var tsplus_module_6 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/io/Fiber/api/join"));
19
-
20
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
21
-
22
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
-
24
- const fileName_1 = "(@fncts/io) src/IO/api/zipWithC.ts";
25
-
26
- /**
27
- * @tsplus fluent fncts.io.IO zipWithC
28
- */
29
- function zipWithC_(self, that, f) {
30
- const g = (b, a) => f(a, b);
31
-
32
- return tsplus_module_1.transplant(graft => tsplus_module_2.descriptorWith(d => tsplus_module_1.raceWith_(graft(self), () => graft(that), (exit, fiber) => coordinateZipWithC()(d.id, f, true, exit, fiber), (exit, fiber) => coordinateZipWithC()(d.id, g, false, exit, fiber), fileName_1 + ":13:27"), fileName_1 + ":12:22"), fileName_1 + ":11:23");
33
- }
34
-
35
- function coordinateZipWithC() {
36
- return (fiberId, f, leftWinner, winner, loser) => {
37
- return tsplus_module_4.match_(winner, cw => tsplus_module_2.flatMap_(tsplus_module_5.interruptAs(loser, fiberId), exit => tsplus_module_4.match_(exit, cl => leftWinner ? tsplus_module_2.failCauseNow(tsplus_module_3.both(cw, cl), fileName_1 + ":34:50") : tsplus_module_2.failCauseNow(tsplus_module_3.both(cl, cw), fileName_1 + ":34:88"), () => tsplus_module_2.failCauseNow(cw, fileName_1 + ":35:34")), fileName_1 + ":32:43"), x => tsplus_module_2.map_(tsplus_module_6.join(loser), y => f(x, y), fileName_1 + ":38:28"));
38
- };
39
- }
40
- //# sourceMappingURL=zipWithC.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"zipWithC.cjs","mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;AAGM,SAAUA,SAAV,CACJC,IADI,EAEJC,IAFI,EAGJC,CAHI,EAGgB;EAEpB,MAAMC,CAAC,GAAG,CAACC,CAAD,EAAOC,CAAP,KAAgBH,CAAC,CAACG,CAAD,EAAID,CAAJ,CAA3B;;EAEA,OAAOE,2BAAeC,KAAD,IACnBC,+BAAmBC,CAAD,IAChBH,+BAAK,CAACN,IAAD,CAAL,EAAW,MACTO,KAAK,CAACN,IAAD,CADP,EAEE,CAACS,IAAD,EAAOC,KAAP,KAAiBC,kBAAkB,GAAUH,CAAC,CAACI,EAAZ,EAAgBX,CAAhB,EAAmB,IAAnB,EAAyBQ,IAAzB,EAA+BC,KAA/B,CAFrC,EAGE,CAACD,IAAD,EAAOC,KAAP,KAAiBC,kBAAkB,GAAUH,CAAC,CAACI,EAAZ,EAAgBV,CAAhB,EAAmB,KAAnB,EAA0BO,IAA1B,EAAgCC,KAAhC,CAHrC,EAG2EG,qBAH3E,CADF,EAKGA,qBALH,CADK,EAOJA,qBAPI,CAAP;AASD;;AAED,SAASF,kBAAT,GAA2B;EACzB,OAAO,CACLG,OADK,EAELb,CAFK,EAGLc,UAHK,EAILC,MAJK,EAKLC,KALK,KAMH;IACF,OAAOC,+BACJC,EAAD,IACEZ,4DAAkBO,OAAlB,GAAoCL,IAAD,IACjCS,6BACGE,EAAD,IAASL,UAAU,GAAGR,6BAAgBc,qBAAWF,EAAX,EAAeC,EAAf,CAAhB,EAAkCP,qBAAlC,CAAH,GAAyCN,6BAAgBc,qBAAWD,EAAX,EAAeD,EAAf,CAAhB,EAAkCN,qBAAlC,CAD9D,EAEE,MAAMN,6BAAgBY,EAAhB,EAAkBN,qBAAlB,CAFR,CADF,EAIGA,qBAJH,CAFG,EAQJS,CAAD,IAAOf,kDAAgBgB,CAAD,IAAOtB,CAAC,CAACqB,CAAD,EAAIC,CAAJ,CAAvB,EAA6BV,qBAA7B,CARF,CAAP;EAUD,CAjBD;AAkBD","names":["zipWithC_","self","that","f","g","b","a","tsplus_module_1","graft","tsplus_module_2","d","exit","fiber","coordinateZipWithC","id","fileName_1","fiberId","leftWinner","winner","loser","tsplus_module_4","cw","cl","tsplus_module_3","x","y"],"sourceRoot":"","sources":["../../../_src/IO/api/zipWithC.ts"],"sourcesContent":[null]}
@@ -1,23 +0,0 @@
1
- const fileName_1 = "(@fncts/io) src/IO/api/zipWithC.ts";
2
- import * as tsplus_module_1 from "@fncts/io/IO/api/core-scope";
3
- import * as tsplus_module_2 from "@fncts/io/IO/api";
4
- import * as tsplus_module_3 from "@fncts/base/data/Cause/api";
5
- import * as tsplus_module_4 from "@fncts/base/data/Exit/api";
6
- import * as tsplus_module_5 from "@fncts/io/Fiber/api/interruptAs";
7
- import * as tsplus_module_6 from "@fncts/io/Fiber/api/join";
8
- /**
9
- * @tsplus fluent fncts.io.IO zipWithC
10
- */
11
-
12
- export function zipWithC_(self, that, f) {
13
- const g = (b, a) => f(a, b);
14
-
15
- return tsplus_module_1.transplant(graft => tsplus_module_2.descriptorWith(d => tsplus_module_1.raceWith_(graft(self), () => graft(that), (exit, fiber) => coordinateZipWithC()(d.id, f, true, exit, fiber), (exit, fiber) => coordinateZipWithC()(d.id, g, false, exit, fiber), fileName_1 + ":13:27"), fileName_1 + ":12:22"), fileName_1 + ":11:23");
16
- }
17
-
18
- function coordinateZipWithC() {
19
- return (fiberId, f, leftWinner, winner, loser) => {
20
- return tsplus_module_4.match_(winner, cw => tsplus_module_2.flatMap_(tsplus_module_5.interruptAs(loser, fiberId), exit => tsplus_module_4.match_(exit, cl => leftWinner ? tsplus_module_2.failCauseNow(tsplus_module_3.both(cw, cl), fileName_1 + ":34:50") : tsplus_module_2.failCauseNow(tsplus_module_3.both(cl, cw), fileName_1 + ":34:88"), () => tsplus_module_2.failCauseNow(cw, fileName_1 + ":35:34")), fileName_1 + ":32:43"), x => tsplus_module_2.map_(tsplus_module_6.join(loser), y => f(x, y), fileName_1 + ":38:28"));
21
- };
22
- }
23
- //# sourceMappingURL=zipWithC.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"zipWithC.mjs","mappings":";;;;;;;AAAA;;;;AAGA,OAAM,SAAUA,SAAV,CACJC,IADI,EAEJC,IAFI,EAGJC,CAHI,EAGgB;EAEpB,MAAMC,CAAC,GAAG,CAACC,CAAD,EAAOC,CAAP,KAAgBH,CAAC,CAACG,CAAD,EAAID,CAAJ,CAA3B;;EAEA,OAAOE,2BAAeC,KAAD,IACnBC,+BAAmBC,CAAD,IAChBH,+BAAK,CAACN,IAAD,CAAL,EAAW,MACTO,KAAK,CAACN,IAAD,CADP,EAEE,CAACS,IAAD,EAAOC,KAAP,KAAiBC,kBAAkB,GAAUH,CAAC,CAACI,EAAZ,EAAgBX,CAAhB,EAAmB,IAAnB,EAAyBQ,IAAzB,EAA+BC,KAA/B,CAFrC,EAGE,CAACD,IAAD,EAAOC,KAAP,KAAiBC,kBAAkB,GAAUH,CAAC,CAACI,EAAZ,EAAgBV,CAAhB,EAAmB,KAAnB,EAA0BO,IAA1B,EAAgCC,KAAhC,CAHrC,EAG2EG,qBAH3E,CADF,EAKGA,qBALH,CADK,EAOJA,qBAPI,CAAP;AASD;;AAED,SAASF,kBAAT,GAA2B;EACzB,OAAO,CACLG,OADK,EAELb,CAFK,EAGLc,UAHK,EAILC,MAJK,EAKLC,KALK,KAMH;IACF,OAAOC,+BACJC,EAAD,IACEZ,4DAAkBO,OAAlB,GAAoCL,IAAD,IACjCS,6BACGE,EAAD,IAASL,UAAU,GAAGR,6BAAgBc,qBAAWF,EAAX,EAAeC,EAAf,CAAhB,EAAkCP,qBAAlC,CAAH,GAAyCN,6BAAgBc,qBAAWD,EAAX,EAAeD,EAAf,CAAhB,EAAkCN,qBAAlC,CAD9D,EAEE,MAAMN,6BAAgBY,EAAhB,EAAkBN,qBAAlB,CAFR,CADF,EAIGA,qBAJH,CAFG,EAQJS,CAAD,IAAOf,kDAAgBgB,CAAD,IAAOtB,CAAC,CAACqB,CAAD,EAAIC,CAAJ,CAAvB,EAA6BV,qBAA7B,CARF,CAAP;EAUD,CAjBD;AAkBD","names":["zipWithC_","self","that","f","g","b","a","tsplus_module_1","graft","tsplus_module_2","d","exit","fiber","coordinateZipWithC","id","fileName_1","fiberId","leftWinner","winner","loser","tsplus_module_4","cw","cl","tsplus_module_3","x","y"],"sourceRoot":"","sources":["../../../_src/IO/api/zipWithC.ts"],"sourcesContent":[null]}
@@ -1,41 +0,0 @@
1
- /**
2
- * @tsplus fluent fncts.io.IO zipWithC
3
- */
4
- export function zipWithC_<R, E, A, R1, E1, B, C>(
5
- self: IO<R, E, A>,
6
- that: IO<R1, E1, B>,
7
- f: (a: A, b: B) => C,
8
- ): IO<R & R1, E | E1, C> {
9
- const g = (b: B, a: A) => f(a, b);
10
-
11
- return IO.transplant((graft) =>
12
- IO.descriptorWith((d) =>
13
- graft(self).raceWith(
14
- graft(that),
15
- (exit, fiber) => coordinateZipWithC<E, E1>()(d.id, f, true, exit, fiber),
16
- (exit, fiber) => coordinateZipWithC<E, E1>()(d.id, g, false, exit, fiber),
17
- ),
18
- ),
19
- );
20
- }
21
-
22
- function coordinateZipWithC<E, E2>() {
23
- return <B, X, Y>(
24
- fiberId: FiberId,
25
- f: (a: X, b: Y) => B,
26
- leftWinner: boolean,
27
- winner: Exit<E | E2, X>,
28
- loser: Fiber<E | E2, Y>,
29
- ) => {
30
- return winner.match(
31
- (cw) =>
32
- loser.interruptAs(fiberId).flatMap((exit) =>
33
- exit.match(
34
- (cl) => (leftWinner ? IO.failCauseNow(Cause.both(cw, cl)) : IO.failCauseNow(Cause.both(cl, cw))),
35
- () => IO.failCauseNow(cw),
36
- ),
37
- ),
38
- (x) => loser.join.map((y) => f(x, y)),
39
- );
40
- };
41
- }