@fncts/io 0.0.34 → 0.0.35

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 (173) hide show
  1. package/Fiber/FiberRuntime.d.ts +7 -7
  2. package/IO/api/all.d.ts +41 -0
  3. package/IO/api/concurrency.d.ts +11 -0
  4. package/IO/api/interrupt.d.ts +1 -1
  5. package/IO/api/raceWith.d.ts +2 -1
  6. package/IO/api.d.ts +7 -2
  7. package/IO/definition.d.ts +103 -127
  8. package/IO.d.ts +1 -0
  9. package/Push/api.d.ts +25 -4
  10. package/Push/definition.d.ts +17 -0
  11. package/STM/definition.d.ts +2 -2
  12. package/Sink/api.d.ts +19 -19
  13. package/_cjs/Channel/api/runScoped.cjs +1 -1
  14. package/_cjs/Channel/api/runScoped.cjs.map +1 -1
  15. package/_cjs/Channel/api.cjs +2 -2
  16. package/_cjs/Channel/api.cjs.map +1 -1
  17. package/_cjs/Fiber/FiberRuntime.cjs +110 -98
  18. package/_cjs/Fiber/FiberRuntime.cjs.map +1 -1
  19. package/_cjs/Future/api.cjs +1 -1
  20. package/_cjs/Future/api.cjs.map +1 -1
  21. package/_cjs/IO/api/all.cjs +33 -0
  22. package/_cjs/IO/api/all.cjs.map +1 -0
  23. package/_cjs/IO/api/asyncIO.cjs +1 -1
  24. package/_cjs/IO/api/asyncIO.cjs.map +1 -1
  25. package/_cjs/IO/api/bracketExit.cjs +1 -1
  26. package/_cjs/IO/api/bracketExit.cjs.map +1 -1
  27. package/_cjs/IO/api/concurrency.cjs +25 -4
  28. package/_cjs/IO/api/concurrency.cjs.map +1 -1
  29. package/_cjs/IO/api/disconnect.cjs +1 -1
  30. package/_cjs/IO/api/disconnect.cjs.map +1 -1
  31. package/_cjs/IO/api/foreachConcurrent.cjs +1 -1
  32. package/_cjs/IO/api/foreachConcurrent.cjs.map +1 -1
  33. package/_cjs/IO/api/foreachExec.cjs +1 -1
  34. package/_cjs/IO/api/foreachExec.cjs.map +1 -1
  35. package/_cjs/IO/api/forkIn.cjs +1 -1
  36. package/_cjs/IO/api/forkIn.cjs.map +1 -1
  37. package/_cjs/IO/api/forkScoped.cjs +1 -1
  38. package/_cjs/IO/api/forkScoped.cjs.map +1 -1
  39. package/_cjs/IO/api/fulfill.cjs +1 -1
  40. package/_cjs/IO/api/fulfill.cjs.map +1 -1
  41. package/_cjs/IO/api/interrupt.cjs +18 -6
  42. package/_cjs/IO/api/interrupt.cjs.map +1 -1
  43. package/_cjs/IO/api/raceWith.cjs +4 -4
  44. package/_cjs/IO/api/raceWith.cjs.map +1 -1
  45. package/_cjs/IO/api/timeout.cjs +8 -5
  46. package/_cjs/IO/api/timeout.cjs.map +1 -1
  47. package/_cjs/IO/api/zipConcurrent.cjs +1 -1
  48. package/_cjs/IO/api/zipConcurrent.cjs.map +1 -1
  49. package/_cjs/IO/api.cjs +78 -20
  50. package/_cjs/IO/api.cjs.map +1 -1
  51. package/_cjs/IO/definition.cjs +14 -191
  52. package/_cjs/IO/definition.cjs.map +1 -1
  53. package/_cjs/IO.cjs +11 -0
  54. package/_cjs/IO.cjs.map +1 -1
  55. package/_cjs/Layer/MemoMap.cjs +1 -1
  56. package/_cjs/Layer/MemoMap.cjs.map +1 -1
  57. package/_cjs/Push/api.cjs +149 -110
  58. package/_cjs/Push/api.cjs.map +1 -1
  59. package/_cjs/Push/definition.cjs.map +1 -1
  60. package/_cjs/STM/api/atomically.cjs +1 -1
  61. package/_cjs/STM/api/atomically.cjs.map +1 -1
  62. package/_cjs/STM/definition.cjs +1 -1
  63. package/_cjs/STM/definition.cjs.map +1 -1
  64. package/_cjs/ScopedRef/api.cjs +2 -2
  65. package/_cjs/ScopedRef/api.cjs.map +1 -1
  66. package/_cjs/Semaphore.cjs +1 -1
  67. package/_cjs/Semaphore.cjs.map +1 -1
  68. package/_cjs/TReentrantLock/api.cjs +2 -2
  69. package/_cjs/TReentrantLock/api.cjs.map +1 -1
  70. package/_cjs/TSemaphore/api.cjs +1 -1
  71. package/_cjs/TSemaphore/api.cjs.map +1 -1
  72. package/_cjs/collection/immutable/Conc/dropUntilIO.cjs +12 -17
  73. package/_cjs/collection/immutable/Conc/dropUntilIO.cjs.map +1 -1
  74. package/_cjs/collection/immutable/Conc/dropWhileIO.cjs +12 -17
  75. package/_cjs/collection/immutable/Conc/dropWhileIO.cjs.map +1 -1
  76. package/_cjs/collection/immutable/Conc/filterIO.cjs +2 -12
  77. package/_cjs/collection/immutable/Conc/filterIO.cjs.map +1 -1
  78. package/_cjs/collection/immutable/Conc/mapIO.cjs +3 -9
  79. package/_cjs/collection/immutable/Conc/mapIO.cjs.map +1 -1
  80. package/_cjs/collection/immutable/Conc/takeWhileIO.cjs +11 -27
  81. package/_cjs/collection/immutable/Conc/takeWhileIO.cjs.map +1 -1
  82. package/_mjs/Channel/api/runScoped.mjs +1 -1
  83. package/_mjs/Channel/api/runScoped.mjs.map +1 -1
  84. package/_mjs/Channel/api.mjs +2 -2
  85. package/_mjs/Channel/api.mjs.map +1 -1
  86. package/_mjs/Fiber/FiberRuntime.mjs +111 -100
  87. package/_mjs/Fiber/FiberRuntime.mjs.map +1 -1
  88. package/_mjs/Future/api.mjs +1 -1
  89. package/_mjs/Future/api.mjs.map +1 -1
  90. package/_mjs/IO/api/all.mjs +24 -0
  91. package/_mjs/IO/api/all.mjs.map +1 -0
  92. package/_mjs/IO/api/asyncIO.mjs +1 -1
  93. package/_mjs/IO/api/asyncIO.mjs.map +1 -1
  94. package/_mjs/IO/api/bracketExit.mjs +1 -1
  95. package/_mjs/IO/api/bracketExit.mjs.map +1 -1
  96. package/_mjs/IO/api/concurrency.mjs +19 -2
  97. package/_mjs/IO/api/concurrency.mjs.map +1 -1
  98. package/_mjs/IO/api/disconnect.mjs +1 -1
  99. package/_mjs/IO/api/disconnect.mjs.map +1 -1
  100. package/_mjs/IO/api/foreachConcurrent.mjs +1 -1
  101. package/_mjs/IO/api/foreachConcurrent.mjs.map +1 -1
  102. package/_mjs/IO/api/foreachExec.mjs +1 -1
  103. package/_mjs/IO/api/foreachExec.mjs.map +1 -1
  104. package/_mjs/IO/api/forkIn.mjs +1 -1
  105. package/_mjs/IO/api/forkIn.mjs.map +1 -1
  106. package/_mjs/IO/api/forkScoped.mjs +1 -1
  107. package/_mjs/IO/api/forkScoped.mjs.map +1 -1
  108. package/_mjs/IO/api/fulfill.mjs +1 -1
  109. package/_mjs/IO/api/fulfill.mjs.map +1 -1
  110. package/_mjs/IO/api/interrupt.mjs +19 -7
  111. package/_mjs/IO/api/interrupt.mjs.map +1 -1
  112. package/_mjs/IO/api/raceWith.mjs +4 -4
  113. package/_mjs/IO/api/raceWith.mjs.map +1 -1
  114. package/_mjs/IO/api/timeout.mjs +8 -5
  115. package/_mjs/IO/api/timeout.mjs.map +1 -1
  116. package/_mjs/IO/api/zipConcurrent.mjs +1 -1
  117. package/_mjs/IO/api/zipConcurrent.mjs.map +1 -1
  118. package/_mjs/IO/api.mjs +78 -23
  119. package/_mjs/IO/api.mjs.map +1 -1
  120. package/_mjs/IO/definition.mjs +12 -181
  121. package/_mjs/IO/definition.mjs.map +1 -1
  122. package/_mjs/IO.mjs +1 -0
  123. package/_mjs/IO.mjs.map +1 -1
  124. package/_mjs/Layer/MemoMap.mjs +1 -1
  125. package/_mjs/Layer/MemoMap.mjs.map +1 -1
  126. package/_mjs/Push/api.mjs +145 -109
  127. package/_mjs/Push/api.mjs.map +1 -1
  128. package/_mjs/Push/definition.mjs.map +1 -1
  129. package/_mjs/STM/api/atomically.mjs +1 -1
  130. package/_mjs/STM/api/atomically.mjs.map +1 -1
  131. package/_mjs/STM/definition.mjs +1 -1
  132. package/_mjs/STM/definition.mjs.map +1 -1
  133. package/_mjs/ScopedRef/api.mjs +2 -2
  134. package/_mjs/ScopedRef/api.mjs.map +1 -1
  135. package/_mjs/Semaphore.mjs +1 -1
  136. package/_mjs/Semaphore.mjs.map +1 -1
  137. package/_mjs/TReentrantLock/api.mjs +2 -2
  138. package/_mjs/TReentrantLock/api.mjs.map +1 -1
  139. package/_mjs/TSemaphore/api.mjs +1 -1
  140. package/_mjs/TSemaphore/api.mjs.map +1 -1
  141. package/_mjs/collection/immutable/Conc/dropUntilIO.mjs +12 -17
  142. package/_mjs/collection/immutable/Conc/dropUntilIO.mjs.map +1 -1
  143. package/_mjs/collection/immutable/Conc/dropWhileIO.mjs +12 -17
  144. package/_mjs/collection/immutable/Conc/dropWhileIO.mjs.map +1 -1
  145. package/_mjs/collection/immutable/Conc/filterIO.mjs +2 -12
  146. package/_mjs/collection/immutable/Conc/filterIO.mjs.map +1 -1
  147. package/_mjs/collection/immutable/Conc/mapIO.mjs +3 -9
  148. package/_mjs/collection/immutable/Conc/mapIO.mjs.map +1 -1
  149. package/_mjs/collection/immutable/Conc/takeWhileIO.mjs +11 -27
  150. package/_mjs/collection/immutable/Conc/takeWhileIO.mjs.map +1 -1
  151. package/_src/Channel/api.ts +3 -3
  152. package/_src/Fiber/FiberRuntime.ts +76 -75
  153. package/_src/IO/api/all.ts +64 -0
  154. package/_src/IO/api/concurrency.ts +33 -0
  155. package/_src/IO/api/foreachExec.ts +2 -2
  156. package/_src/IO/api/interrupt.ts +20 -7
  157. package/_src/IO/api/raceWith.ts +4 -2
  158. package/_src/IO/api/timeout.ts +21 -1
  159. package/_src/IO/api.ts +79 -27
  160. package/_src/IO/definition.ts +155 -199
  161. package/_src/IO.ts +1 -0
  162. package/_src/Push/api.ts +70 -4
  163. package/_src/Push/definition.ts +6 -0
  164. package/_src/STM/definition.ts +2 -2
  165. package/_src/collection/immutable/Conc/dropUntilIO.ts +18 -15
  166. package/_src/collection/immutable/Conc/dropWhileIO.ts +18 -17
  167. package/_src/collection/immutable/Conc/filterIO.ts +1 -11
  168. package/_src/collection/immutable/Conc/mapIO.ts +2 -9
  169. package/_src/collection/immutable/Conc/takeWhileIO.ts +19 -28
  170. package/collection/immutable/Conc/filterIO.d.ts +1 -1
  171. package/collection/immutable/Conc/mapIO.d.ts +1 -1
  172. package/collection/immutable/Conc/takeWhileIO.d.ts +1 -1
  173. package/package.json +2 -2
package/_src/IO/api.ts CHANGED
@@ -6,17 +6,8 @@ import type { RuntimeFlags } from "@fncts/io/RuntimeFlags";
6
6
 
7
7
  import { IOError } from "@fncts/base/data/exceptions";
8
8
  import { identity, pipe, tuple } from "@fncts/base/data/function";
9
- import {
10
- Async,
11
- GenerateStackTrace,
12
- OnSuccess,
13
- OnSuccessAndFailure,
14
- Sync,
15
- UpdateRuntimeFlags,
16
- YieldNow,
17
- } from "@fncts/io/IO/definition";
18
- import { Stateful } from "@fncts/io/IO/definition";
19
- import { Fail, IO, SucceedNow } from "@fncts/io/IO/definition";
9
+ import { IOPrimitive,IOTag } from "@fncts/io/IO/definition";
10
+ import { IO } from "@fncts/io/IO/definition";
20
11
 
21
12
  /**
22
13
  * Imports an asynchronous side-effect into a `IO`
@@ -28,7 +19,11 @@ export function async<R, E, A>(
28
19
  blockingOn: FiberId = FiberId.none,
29
20
  __tsplusTrace?: string,
30
21
  ): IO<R, E, A> {
31
- return new Async(register, () => blockingOn, __tsplusTrace);
22
+ const io = new IOPrimitive(IOTag.Async) as any;
23
+ io.i0 = register;
24
+ io.i1 = () => blockingOn;
25
+ io.trace = __tsplusTrace;
26
+ return io;
32
27
  }
33
28
 
34
29
  /**
@@ -318,7 +313,11 @@ export function checkInterruptible<R, E, A>(
318
313
  */
319
314
  export function flatMap<A, R1, E1, B>(f: (a: A) => IO<R1, E1, B>, __tsplusTrace?: string) {
320
315
  return <R, E>(ma: IO<R, E, A>): IO<R | R1, E | E1, B> => {
321
- return new OnSuccess(ma, f, __tsplusTrace);
316
+ const io = new IOPrimitive(IOTag.OnSuccess) as any;
317
+ io.i0 = ma;
318
+ io.i1 = f;
319
+ io.trace = __tsplusTrace;
320
+ return io;
322
321
  };
323
322
  }
324
323
 
@@ -369,7 +368,7 @@ export function condIO<R, R1, E, A>(
369
368
  *
370
369
  * @tsplus static fncts.io.IOOps defer
371
370
  */
372
- export function defer<R, E, A>(io: Lazy<IO<R, E, A>>, __tsplusTrace?: string): IO<R, E, A> {
371
+ export function defer<R = never, E = never, A = never>(io: Lazy<IO<R, E, A>>, __tsplusTrace?: string): IO<R, E, A> {
373
372
  return IO.succeed(io).flatMap(identity);
374
373
  }
375
374
 
@@ -379,7 +378,10 @@ export function defer<R, E, A>(io: Lazy<IO<R, E, A>>, __tsplusTrace?: string): I
379
378
  *
380
379
  * @tsplus static fncts.io.IOOps deferTry
381
380
  */
382
- export function deferTry<R, E, A>(io: () => IO<R, E, A>, __tsplusTrace?: string): IO<R, unknown, A> {
381
+ export function deferTry<R = never, E = never, A = never>(
382
+ io: () => IO<R, E, A>,
383
+ __tsplusTrace?: string,
384
+ ): IO<R, unknown, A> {
383
385
  return IO.defer(() => {
384
386
  try {
385
387
  return io();
@@ -463,7 +465,10 @@ export function failNow<E>(e: E, __tsplusTrace?: string): FIO<E, never> {
463
465
  * @tsplus static fncts.io.IOOps refailCause
464
466
  */
465
467
  export function refailCause<E>(cause: Cause<E>, __tsplusTrace?: string): FIO<E, never> {
466
- return new Fail(() => cause, __tsplusTrace);
468
+ const io = new IOPrimitive(IOTag.Fail) as any;
469
+ io.i0 = () => cause;
470
+ io.trace = __tsplusTrace;
471
+ return io;
467
472
  }
468
473
 
469
474
  /**
@@ -472,7 +477,10 @@ export function refailCause<E>(cause: Cause<E>, __tsplusTrace?: string): FIO<E,
472
477
  * @tsplus static fncts.io.IOOps failCauseNow
473
478
  */
474
479
  export function failCauseNow<E>(cause: Cause<E>, __tsplusTrace?: string): FIO<E, never> {
475
- return new Fail(() => cause, __tsplusTrace);
480
+ const io = new IOPrimitive(IOTag.Fail) as any;
481
+ io.i0 = () => cause;
482
+ io.trace = __tsplusTrace;
483
+ return io;
476
484
  }
477
485
 
478
486
  /**
@@ -1223,7 +1231,12 @@ export function matchCauseIO<E, A, R1, E1, A1, R2, E2, A2>(
1223
1231
  __tsplusTrace?: string,
1224
1232
  ) {
1225
1233
  return <R>(self: IO<R, E, A>): IO<R | R1 | R2, E1 | E2, A1 | A2> => {
1226
- return new OnSuccessAndFailure(self, onFailure, onSuccess, __tsplusTrace);
1234
+ const io = new IOPrimitive(IOTag.OnSuccessAndFailure) as any;
1235
+ io.i0 = self;
1236
+ io.i1 = onFailure;
1237
+ io.i2 = onSuccess;
1238
+ io.trace = __tsplusTrace;
1239
+ return io;
1227
1240
  };
1228
1241
  }
1229
1242
 
@@ -1664,7 +1677,10 @@ export function sequenceIterableDiscard<R, E, A>(as: Iterable<IO<R, E, A>>, __ts
1664
1677
  * @tsplus static fncts.io.IOOps succeedNow
1665
1678
  */
1666
1679
  export function succeedNow<A>(value: A, __tsplusTrace?: string): IO<never, never, A> {
1667
- return new SucceedNow(value, __tsplusTrace);
1680
+ const io = new IOPrimitive(IOTag.SucceedNow) as any;
1681
+ io.i0 = value;
1682
+ io.trace = __tsplusTrace;
1683
+ return io;
1668
1684
  }
1669
1685
 
1670
1686
  /**
@@ -1676,7 +1692,10 @@ export function succeedNow<A>(value: A, __tsplusTrace?: string): IO<never, never
1676
1692
  * @tsplus static fncts.io.IOOps __call
1677
1693
  */
1678
1694
  export function succeed<A>(effect: Lazy<A>, __tsplusTrace?: string): UIO<A> {
1679
- return new Sync(effect, __tsplusTrace);
1695
+ const io = new IOPrimitive(IOTag.Sync) as any;
1696
+ io.i0 = effect;
1697
+ io.trace = __tsplusTrace;
1698
+ return io;
1680
1699
  }
1681
1700
 
1682
1701
  /**
@@ -1721,17 +1740,42 @@ export function timedWith<R1, E1>(msTime: IO<R1, E1, number>, __tsplusTrace?: st
1721
1740
  ma.summarized(msTime, (start, end) => end - start);
1722
1741
  }
1723
1742
 
1743
+ /**
1744
+ * @tsplus static fncts.io.IOOps attempt
1745
+ */
1746
+ export function attempt<A>(effect: Lazy<A>, __tsplusTrace?: string): FIO<unknown, A> {
1747
+ return IO.defer(() => {
1748
+ try {
1749
+ return Exit.succeed(effect());
1750
+ } catch (u) {
1751
+ return IO.withFiberRuntime((fiberState) => {
1752
+ if (!fiberState.isFatal(u)) {
1753
+ throw new IOError(Cause.fail(u));
1754
+ } else {
1755
+ throw u;
1756
+ }
1757
+ });
1758
+ }
1759
+ });
1760
+ }
1761
+
1724
1762
  /**
1725
1763
  * Creates a `IO` that has succeeded with a pure value
1726
1764
  *
1727
1765
  * @tsplus static fncts.io.IOOps tryCatch
1728
1766
  */
1729
1767
  export function tryCatch<E, A>(effect: Lazy<A>, onThrow: (error: unknown) => E, __tsplusTrace?: string): FIO<E, A> {
1730
- return IO.succeed(() => {
1768
+ return IO.defer(() => {
1731
1769
  try {
1732
- return effect();
1770
+ return Exit.succeed(effect());
1733
1771
  } catch (u) {
1734
- throw new IOError(Cause.fail(onThrow(u)));
1772
+ return IO.withFiberRuntime((fiberState) => {
1773
+ if (!fiberState.isFatal(u)) {
1774
+ throw new IOError(Cause.fail(u));
1775
+ } else {
1776
+ throw u;
1777
+ }
1778
+ });
1735
1779
  }
1736
1780
  });
1737
1781
  }
@@ -1902,21 +1946,29 @@ export function withFiberRuntime<R, E, A>(
1902
1946
  onState: (fiber: FiberRuntime<E, A>, status: Running) => IO<R, E, A>,
1903
1947
  __tsplusTrace?: string,
1904
1948
  ): IO<R, E, A> {
1905
- return new Stateful(onState, __tsplusTrace);
1949
+ const io = new IOPrimitive(IOTag.Stateful) as any;
1950
+ io.i0 = onState;
1951
+ io.trace = __tsplusTrace;
1952
+ return io;
1906
1953
  }
1907
1954
 
1908
1955
  /**
1909
1956
  * @tsplus static fncts.io.IOOps updateRuntimeFlags
1910
1957
  */
1911
1958
  export function updateRuntimeFlags(patch: RuntimeFlags.Patch, __tsplusTrace?: string): IO<never, never, void> {
1912
- return new UpdateRuntimeFlags(patch, __tsplusTrace);
1959
+ const io = new IOPrimitive(IOTag.UpdateRuntimeFlags) as any;
1960
+ io.i0 = patch;
1961
+ io.trace = __tsplusTrace;
1962
+ return io;
1913
1963
  }
1914
1964
 
1915
1965
  /**
1916
1966
  * @tsplus static fncts.io.IOOps stackTrace
1917
1967
  */
1918
1968
  export function stackTrace(__tsplusTrace?: string): UIO<Trace> {
1919
- return new GenerateStackTrace(__tsplusTrace);
1969
+ const io = new IOPrimitive(IOTag.GenerateStackTrace) as any;
1970
+ io.trace = __tsplusTrace;
1971
+ return io;
1920
1972
  }
1921
1973
 
1922
1974
  /**
@@ -1926,7 +1978,7 @@ export function stackTrace(__tsplusTrace?: string): UIO<Trace> {
1926
1978
  *
1927
1979
  * @tsplus static fncts.io.IOOps yieldNow
1928
1980
  */
1929
- export const yieldNow: UIO<void> = new YieldNow();
1981
+ export const yieldNow: UIO<void> = new IOPrimitive(IOTag.YieldNow) as any;
1930
1982
 
1931
1983
  /**
1932
1984
  * @tsplus pipeable fncts.io.IO zip
@@ -1,13 +1,11 @@
1
1
  import type { FiberRuntime } from "../Fiber/FiberRuntime.js";
2
2
  import type { Running } from "../FiberStatus.js";
3
3
  import type { RuntimeFlagsPatch } from "../RuntimeFlags.js";
4
+ import type { RuntimeFlags } from "../RuntimeFlags.js";
4
5
  import type { Left, Right } from "@fncts/base/data/Either";
5
6
  import type { Failure, Success } from "@fncts/base/data/Exit";
6
7
  import type { Trace } from "@fncts/base/data/Trace";
7
8
 
8
- import { RuntimeFlag } from "../RuntimeFlag.js";
9
- import { RuntimeFlags } from "../RuntimeFlags.js";
10
-
11
9
  export const IOVariance = Symbol.for("fncts.io.IO.Variance");
12
10
  export type IOVariance = typeof IOVariance;
13
11
 
@@ -36,6 +34,10 @@ export abstract class IO<R, E, A> {
36
34
  };
37
35
  }
38
36
 
37
+ export type EnvironmentOf<T> = [T] extends [{ [IOVariance]: { _R: () => infer R } }] ? R : never;
38
+ export type ErrorOf<T> = [T] extends [{ [IOVariance]: { _E: () => infer E } }] ? E : never;
39
+ export type ValueOf<T> = [T] extends [{ [IOVariance]: { _A: () => infer A } }] ? A : never;
40
+
39
41
  declare module "@fncts/base/data/Either/definition" {
40
42
  interface Either<E, A> extends IO<never, E, A> {}
41
43
  }
@@ -76,7 +78,7 @@ export type URIO<R, A> = IO<R, never, A>;
76
78
 
77
79
  export type FIO<E, A> = IO<never, E, A>;
78
80
 
79
- export const enum IOOpCode {
81
+ export const enum IOTag {
80
82
  SucceedNow,
81
83
  Fail,
82
84
  Sync,
@@ -95,199 +97,161 @@ export const enum IOOpCode {
95
97
  UpdateTrace,
96
98
  }
97
99
 
98
- export function isIO(u: unknown): u is IO<any, any, any> {
99
- return isObject(u) && IOTypeId in u;
100
- }
101
-
102
- export class Sync<A> extends IO<never, never, A> {
103
- readonly _tag = IOOpCode.Sync;
104
- constructor(readonly evaluate: () => A, readonly trace?: string) {
105
- super();
106
- }
107
- }
108
-
109
- export class Async<R, E, A> extends IO<R, E, A> {
110
- readonly _tag = IOOpCode.Async;
111
- constructor(
112
- readonly registerCallback: (f: (_: IO<R, E, A>) => void) => any,
113
- readonly blockingOn: () => FiberId,
114
- readonly trace?: string,
115
- ) {
116
- super();
117
- }
118
- }
119
-
120
- /**
121
- * @internal
122
- */
123
- export class OnSuccessAndFailure<R, E, A, R1, E1, B, R2, E2, C> extends IO<R | R1 | R2, E1 | E2, B | C> {
124
- readonly _tag = IOOpCode.OnSuccessAndFailure;
125
-
126
- constructor(
127
- readonly first: IO<R, E, A>,
128
- readonly failureK: (cause: Cause<E>) => IO<R1, E1, B>,
129
- readonly successK: (a: A) => IO<R2, E2, C>,
130
- readonly trace?: string,
131
- ) {
132
- super();
133
- }
134
-
135
- onFailure(c: Cause<E>): IO<R | R1 | R2, E1 | E2, B | C> {
136
- return this.failureK(c);
137
- }
138
- onSuccess(a: A): IO<R | R1 | R2, E1 | E2, B | C> {
139
- return this.successK(a);
140
- }
141
- }
142
-
143
- export class OnFailure<R, E, A, R1, E1, B> extends IO<R | R1, E1, A | B> {
144
- readonly _tag = IOOpCode.OnFailure;
145
- constructor(
146
- readonly first: IO<R, E, A>,
147
- readonly failureK: (cause: Cause<E>) => IO<R1, E1, B>,
148
- readonly trace?: string,
149
- ) {
150
- super();
151
- }
152
-
153
- onFailure(c: Cause<E>): IO<R | R1, E1, A | B> {
154
- return this.failureK(c);
155
- }
156
- onSuccess(a: A): IO<R | R1, E1, A | B> {
157
- return new SucceedNow(a);
158
- }
159
- }
160
-
161
- /**
162
- * @internal
163
- */
164
- export class OnSuccess<R, R1, E, E1, A, A1> extends IO<R | R1, E | E1, A1> {
165
- readonly _tag = IOOpCode.OnSuccess;
166
- constructor(readonly first: IO<R, E, A>, readonly successK: (a: A) => IO<R1, E1, A1>, readonly trace?: string) {
167
- super();
168
- }
169
- onFailure(c: Cause<E>): IO<R | R1, E | E1, A1> {
170
- return new Fail(c);
171
- }
172
- onSuccess(a: A): IO<R | R1, E | E1, A1> {
173
- return this.successK(a);
174
- }
175
- }
176
-
177
- /**
178
- * @internal
179
- */
180
- export class SucceedNow<A> extends IO<never, never, A> {
181
- readonly _tag = IOOpCode.SucceedNow;
182
- constructor(readonly value: A, readonly trace?: string) {
183
- super();
184
- }
185
- }
186
-
187
- export class UpdateRuntimeFlags extends IO<never, never, void> {
188
- readonly _tag = IOOpCode.UpdateRuntimeFlags;
189
- constructor(readonly update: RuntimeFlags.Patch, readonly trace?: string) {
190
- super();
191
- }
192
- }
193
-
194
- export class Interruptible<R, E, A> extends IO<R, E, A> {
195
- readonly _tag = IOOpCode.UpdateRuntimeFlagsWithin;
196
- constructor(readonly effect: IO<R, E, A>, readonly trace?: string) {
197
- super();
198
- }
199
-
200
- readonly update: RuntimeFlags.Patch = RuntimeFlags.enable(RuntimeFlag.Interruption);
201
- scope(oldRuntimeFlags: RuntimeFlags): IO<R, E, A> {
202
- return this.effect;
203
- }
204
- }
205
-
206
- export class Uninterruptible<R, E, A> extends IO<R, E, A> {
207
- readonly _tag = IOOpCode.UpdateRuntimeFlagsWithin;
208
- constructor(readonly effect: IO<R, E, A>, readonly trace?: string) {
209
- super();
210
- }
211
-
212
- readonly update: RuntimeFlags.Patch = RuntimeFlags.disable(RuntimeFlag.Interruption);
213
- scope(oldRuntimeFlags: RuntimeFlags): IO<R, E, A> {
214
- return this.effect;
215
- }
216
- }
217
-
218
- export class Dynamic<R, E, A> extends IO<R, E, A> {
219
- readonly _tag = IOOpCode.UpdateRuntimeFlagsWithin;
220
- constructor(
221
- readonly update: RuntimeFlagsPatch,
222
- readonly f: (oldRuntimeFlags: RuntimeFlags) => IO<R, E, A>,
223
- readonly trace?: string,
224
- ) {
225
- super();
226
- }
227
-
228
- scope(oldRuntimeFlags: RuntimeFlags): IO<R, E, A> {
229
- return this.f(oldRuntimeFlags);
230
- }
231
- }
232
-
233
- export class GenerateStackTrace extends IO<never, never, Trace> {
234
- readonly _tag = IOOpCode.GenerateStackTrace;
235
- constructor(readonly trace?: string) {
236
- super();
237
- }
238
- }
239
-
240
- export class Stateful<R, E, A> extends IO<R, E, A> {
241
- readonly _tag = IOOpCode.Stateful;
242
- constructor(readonly onState: (fiber: FiberRuntime<E, A>, status: Running) => IO<R, E, A>, readonly trace?: string) {
243
- super();
244
- }
245
- }
246
-
247
- export class WhileLoop<R, E, A> extends IO<R, E, void> {
248
- readonly _tag = IOOpCode.WhileLoop;
249
- constructor(
250
- readonly check: () => boolean,
251
- readonly body: () => IO<R, E, A>,
252
- readonly process: (a: A) => any,
253
- readonly trace?: string,
254
- ) {
255
- super();
256
- }
257
- }
100
+ export type IOOp<Tag extends string | number, Body = {}> = IO<never, never, never> &
101
+ Body & {
102
+ readonly _tag: Tag;
103
+ };
258
104
 
259
- export class YieldNow extends IO<never, never, void> {
260
- readonly _tag = IOOpCode.YieldNow;
261
- constructor(readonly trace?: string) {
262
- super();
263
- }
105
+ export class IOPrimitive {
106
+ public i0: any = undefined;
107
+ public i1: any = undefined;
108
+ public i2: any = undefined;
109
+ public trace: string | undefined = undefined;
110
+ [IOTypeId] = IOTypeId;
111
+ constructor(readonly _tag: Primitive["_tag"]) {}
264
112
  }
265
113
 
266
- /**
267
- * @internal
268
- */
269
- export class Fail<E> extends IO<never, E, never> {
270
- readonly _tag = IOOpCode.Fail;
271
-
272
- constructor(readonly cause: Lazy<Cause<E>>, readonly trace?: string) {
273
- super();
274
- }
114
+ export function isIO(u: unknown): u is IO<any, any, any> {
115
+ return isObject(u) && IOTypeId in u;
275
116
  }
276
117
 
277
- export type Concrete =
278
- | OnSuccessAndFailure<any, any, any, any, any, any, any, any, any>
279
- | OnFailure<any, any, any, any, any, any>
280
- | OnSuccess<any, any, any, any, any, any>
118
+ export interface Sync<A = any>
119
+ extends IOOp<
120
+ IOTag.Sync,
121
+ {
122
+ readonly i0: () => A;
123
+ readonly trace: string | undefined;
124
+ }
125
+ > {}
126
+
127
+ export interface Async<R = any, E = any, A = any>
128
+ extends IOOp<
129
+ IOTag.Async,
130
+ {
131
+ readonly i0: (resume: (io: Primitive) => void) => void;
132
+ readonly i1: () => FiberId;
133
+ readonly trace: string | undefined;
134
+ }
135
+ > {}
136
+
137
+ export interface OnSuccessAndFailure
138
+ extends IOOp<
139
+ IOTag.OnSuccessAndFailure,
140
+ {
141
+ readonly i0: Primitive;
142
+ readonly i1: (cause: Cause<unknown>) => Primitive;
143
+ readonly i2: (a: unknown) => Primitive;
144
+ readonly trace: string | undefined;
145
+ }
146
+ > {}
147
+
148
+ export interface OnFailure
149
+ extends IOOp<
150
+ IOTag.OnFailure,
151
+ {
152
+ readonly i0: Primitive;
153
+ readonly i1: (cause: Cause<unknown>) => Primitive;
154
+ readonly trace: string | undefined;
155
+ }
156
+ > {}
157
+
158
+ export interface OnSuccess
159
+ extends IOOp<
160
+ IOTag.OnSuccess,
161
+ {
162
+ readonly i0: Primitive;
163
+ readonly i1: (a: unknown) => Primitive;
164
+ readonly trace: string | undefined;
165
+ }
166
+ > {}
167
+
168
+ export interface SucceedNow
169
+ extends IOOp<
170
+ IOTag.SucceedNow,
171
+ {
172
+ readonly i0: any;
173
+ readonly trace: string | undefined;
174
+ }
175
+ > {}
176
+
177
+ export interface UpdateRuntimeFlags
178
+ extends IOOp<
179
+ IOTag.UpdateRuntimeFlags,
180
+ {
181
+ readonly i0: RuntimeFlags.Patch;
182
+ readonly trace: string | undefined;
183
+ }
184
+ > {}
185
+
186
+ export interface UpdateRuntimeFlagsWithin
187
+ extends IOOp<
188
+ IOTag.UpdateRuntimeFlagsWithin,
189
+ {
190
+ readonly i0: RuntimeFlagsPatch;
191
+ readonly i1: (oldRuntimeFlags: RuntimeFlags) => Primitive;
192
+ readonly trace: string | undefined;
193
+ }
194
+ > {}
195
+
196
+ export interface GenerateStackTrace
197
+ extends IOOp<
198
+ IOTag.GenerateStackTrace,
199
+ {
200
+ readonly trace: string | undefined;
201
+ }
202
+ > {}
203
+
204
+ export interface Stateful
205
+ extends IOOp<
206
+ IOTag.Stateful,
207
+ {
208
+ readonly i0: (fiber: FiberRuntime<any, any>, status: Running) => Primitive;
209
+ readonly trace: string | undefined;
210
+ }
211
+ > {}
212
+
213
+ export interface WhileLoop
214
+ extends IOOp<
215
+ IOTag.WhileLoop,
216
+ {
217
+ readonly i0: () => boolean;
218
+ readonly i1: () => Primitive;
219
+ readonly i2: (a: any) => any;
220
+ readonly trace: string | undefined;
221
+ }
222
+ > {}
223
+
224
+ export interface YieldNow
225
+ extends IOOp<
226
+ IOTag.YieldNow,
227
+ {
228
+ readonly trace: string | undefined;
229
+ }
230
+ > {}
231
+
232
+ export interface Fail
233
+ extends IOOp<
234
+ IOTag.Fail,
235
+ {
236
+ readonly i0: () => Cause<unknown>;
237
+ readonly trace: string | undefined;
238
+ }
239
+ > {}
240
+
241
+ export type Primitive =
242
+ | OnSuccessAndFailure
243
+ | OnFailure
244
+ | OnSuccess
281
245
  | UpdateRuntimeFlagsWithin
282
- | Sync<any>
283
- | Async<any, any, any>
284
- | SucceedNow<any>
246
+ | Sync
247
+ | Async
248
+ | SucceedNow
285
249
  | UpdateRuntimeFlags
286
250
  | GenerateStackTrace
287
- | Stateful<any, any, any>
288
- | WhileLoop<any, any, any>
251
+ | Stateful
252
+ | WhileLoop
289
253
  | YieldNow
290
- | Fail<any>
254
+ | Fail
291
255
  | STM<any, any, any>
292
256
  | Left<any>
293
257
  | Right<any>
@@ -300,18 +264,10 @@ export type Concrete =
300
264
  * @tsplus static fncts.io.IOOps concrete
301
265
  * @tsplus macro identity
302
266
  */
303
- export function concrete(io: IO<any, any, any>): Concrete {
304
- return io as Concrete;
267
+ export function concrete(io: IO<any, any, any>): Primitive {
268
+ return io as Primitive;
305
269
  }
306
270
 
307
- export type EvaluationStep =
308
- | OnSuccessAndFailure<any, any, any, any, any, any, any, any, any>
309
- | OnFailure<any, any, any, any, any, any>
310
- | OnSuccess<any, any, any, any, any, any>;
311
-
312
- export type UpdateRuntimeFlagsWithin =
313
- | Interruptible<any, any, any>
314
- | Uninterruptible<any, any, any>
315
- | Dynamic<any, any, any>;
271
+ export type EvaluationStep = OnSuccessAndFailure | OnFailure | OnSuccess;
316
272
 
317
273
  export type Canceler<R> = URIO<R, void>;
package/_src/IO.ts CHANGED
@@ -11,6 +11,7 @@ export * from "./IO/api/acquireReleaseInterruptible.js";
11
11
  export * from "./IO/api/acquireReleaseInterruptibleExit.js";
12
12
  export * from "./IO/api/addFinalizer.js";
13
13
  export * from "./IO/api/addFinalizerExit.js";
14
+ export * from "./IO/api/all.js";
14
15
  export * from "./IO/api/asyncInterrupt.js";
15
16
  export * from "./IO/api/asyncIO.js";
16
17
  export * from "./IO/api/blocking.js";