@fncts/io 0.0.1 → 0.0.4

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 (279) hide show
  1. package/Channel/api.d.ts +2 -2
  2. package/Clock/api.d.ts +3 -1
  3. package/Clock/definition.d.ts +3 -1
  4. package/Clock/live.d.ts +2 -0
  5. package/Fiber/api/interruptFork.d.ts +1 -1
  6. package/IO/api/asyncIO.d.ts +6 -0
  7. package/IO/api/ensuringChildren.d.ts +7 -0
  8. package/IO/api/sequenceT.d.ts +2 -3
  9. package/IO/api/sleep.d.ts +3 -1
  10. package/IO/api/timeout.d.ts +14 -0
  11. package/IO/api.d.ts +2 -2
  12. package/IO/definition.d.ts +8 -4
  13. package/IO.d.ts +3 -0
  14. package/IOSpec.d.ts +10 -1
  15. package/Latch.d.ts +3 -0
  16. package/Schedule/Decision.d.ts +1 -1
  17. package/Schedule/api.d.ts +1 -1
  18. package/Schedule.d.ts +0 -1
  19. package/Scope/Finalizer/definition.d.ts +1 -1
  20. package/Scope/ReleaseMap/definition.d.ts +1 -1
  21. package/Stream/api.d.ts +5 -22
  22. package/Stream/internal/DebounceState.d.ts +3 -3
  23. package/Stream/internal/Handoff.d.ts +9 -9
  24. package/Stream/internal/SinkEndReason.d.ts +6 -18
  25. package/TFuture/definition.d.ts +1 -1
  26. package/TSemaphore/definition.d.ts +1 -1
  27. package/_cjs/Cached.cjs +3 -3
  28. package/_cjs/Channel/ChildExecutorDecision.cjs +2 -2
  29. package/_cjs/Channel/UpstreamPullRequest.cjs +2 -2
  30. package/_cjs/Channel/UpstreamPullStrategy.cjs +1 -1
  31. package/_cjs/Channel/api/interruptWhen.cjs +1 -1
  32. package/_cjs/Channel/api/interruptWhen.cjs.map +1 -1
  33. package/_cjs/Channel/api/mapOutIOC.cjs +1 -1
  34. package/_cjs/Channel/api/mapOutIOC.cjs.map +1 -1
  35. package/_cjs/Channel/api/mergeAllWith.cjs +1 -1
  36. package/_cjs/Channel/api/mergeAllWith.cjs.map +1 -1
  37. package/_cjs/Channel/api/mergeWith.cjs +6 -6
  38. package/_cjs/Channel/api/mergeWith.cjs.map +1 -1
  39. package/_cjs/Channel/api.cjs +14 -14
  40. package/_cjs/Channel/api.cjs.map +1 -1
  41. package/_cjs/Channel/core-api.cjs +1 -1
  42. package/_cjs/Channel/internal/ChannelExecutor.cjs +2 -2
  43. package/_cjs/Channel/internal/ChannelExecutor.cjs.map +1 -1
  44. package/_cjs/Channel/internal/SingleProducerAsyncInput.cjs +8 -7
  45. package/_cjs/Channel/internal/SingleProducerAsyncInput.cjs.map +1 -1
  46. package/_cjs/Channel.cjs +3 -3
  47. package/_cjs/Clock/api.cjs.map +1 -1
  48. package/_cjs/Clock/live.cjs +1 -1
  49. package/_cjs/Clock/live.cjs.map +1 -1
  50. package/_cjs/Clock.cjs +3 -3
  51. package/_cjs/Console.cjs +3 -3
  52. package/_cjs/Fiber/FiberContext.cjs +57 -56
  53. package/_cjs/Fiber/FiberContext.cjs.map +1 -1
  54. package/_cjs/Fiber/api/interruptFork.cjs +1 -1
  55. package/_cjs/Fiber/api/interruptFork.cjs.map +1 -1
  56. package/_cjs/Fiber.cjs +23 -23
  57. package/_cjs/FiberRef/constructors.cjs +1 -1
  58. package/_cjs/FiberRef/constructors.cjs.map +1 -1
  59. package/_cjs/FiberRef.cjs +5 -5
  60. package/_cjs/FiberRefs/join.cjs +2 -2
  61. package/_cjs/FiberRefs/join.cjs.map +1 -1
  62. package/_cjs/FiberRefs.cjs +3 -3
  63. package/_cjs/FiberScope.cjs +2 -2
  64. package/_cjs/FiberState/constructors.cjs +1 -1
  65. package/_cjs/FiberState.cjs +3 -3
  66. package/_cjs/FiberStatus/constructors.cjs +1 -1
  67. package/_cjs/FiberStatus.cjs +2 -2
  68. package/_cjs/Future.cjs +3 -3
  69. package/_cjs/Hub.cjs +2 -2
  70. package/_cjs/IO/api/asyncIO.cjs +37 -0
  71. package/_cjs/IO/api/asyncIO.cjs.map +1 -0
  72. package/_cjs/IO/api/core-scope.cjs +1 -1
  73. package/_cjs/IO/api/ensuringChildren.cjs +24 -0
  74. package/_cjs/IO/api/ensuringChildren.cjs.map +1 -0
  75. package/_cjs/IO/api/interrupt.cjs +5 -5
  76. package/_cjs/IO/api/interrupt.cjs.map +1 -1
  77. package/_cjs/IO/api/sleep.cjs.map +1 -1
  78. package/_cjs/IO/api/timeout.cjs +42 -0
  79. package/_cjs/IO/api/timeout.cjs.map +1 -0
  80. package/_cjs/IO/api.cjs +41 -40
  81. package/_cjs/IO/api.cjs.map +1 -1
  82. package/_cjs/IO/definition.cjs +9 -6
  83. package/_cjs/IO/definition.cjs.map +1 -1
  84. package/_cjs/IO/runtime.cjs +1 -1
  85. package/_cjs/IO/runtime.cjs.map +1 -1
  86. package/_cjs/IO.cjs +86 -47
  87. package/_cjs/IO.cjs.map +1 -1
  88. package/_cjs/IOEnv.cjs +3 -3
  89. package/_cjs/InterruptStatus.cjs +2 -2
  90. package/_cjs/Layer/api.cjs +5 -3
  91. package/_cjs/Layer/api.cjs.map +1 -1
  92. package/_cjs/Layer.cjs +3 -3
  93. package/_cjs/Logger.cjs +3 -3
  94. package/_cjs/Queue/api.cjs +7 -7
  95. package/_cjs/Queue.cjs +5 -5
  96. package/_cjs/Random.cjs +3 -3
  97. package/_cjs/Ref/Atomic/Atomic.cjs +3 -3
  98. package/_cjs/Ref/Atomic/api.cjs +10 -6
  99. package/_cjs/Ref/Atomic/api.cjs.map +1 -1
  100. package/_cjs/Ref/Atomic.cjs +2 -2
  101. package/_cjs/Ref/Derived.cjs +2 -2
  102. package/_cjs/Ref/DerivedAll.cjs +1 -1
  103. package/_cjs/Ref/Synchronized/api.cjs +1 -1
  104. package/_cjs/Ref/Synchronized/constructors.cjs +1 -1
  105. package/_cjs/Ref/Synchronized/definition.cjs +1 -1
  106. package/_cjs/Ref/api/get.cjs +1 -1
  107. package/_cjs/Ref/api/match.cjs +1 -1
  108. package/_cjs/Ref/api/matchAll.cjs +1 -1
  109. package/_cjs/Ref/api/modify.cjs +1 -1
  110. package/_cjs/Ref/api/set.cjs +1 -1
  111. package/_cjs/Ref/api.cjs +8 -8
  112. package/_cjs/Ref/constructors.cjs +1 -1
  113. package/_cjs/Ref.cjs +9 -9
  114. package/_cjs/STM/api/core-api.cjs +1 -1
  115. package/_cjs/STM/api/core-constructors.cjs +1 -1
  116. package/_cjs/STM/api.cjs +2 -2
  117. package/_cjs/STM/driver.cjs +1 -1
  118. package/_cjs/STM/internal/Entry.cjs +1 -1
  119. package/_cjs/STM/internal/Journal.cjs +2 -2
  120. package/_cjs/STM.cjs +5 -5
  121. package/_cjs/Schedule/Decision.cjs.map +1 -1
  122. package/_cjs/Schedule/api/driver.cjs +11 -9
  123. package/_cjs/Schedule/api/driver.cjs.map +1 -1
  124. package/_cjs/Schedule/api.cjs +49 -49
  125. package/_cjs/Schedule/api.cjs.map +1 -1
  126. package/_cjs/Schedule.cjs +4 -17
  127. package/_cjs/Schedule.cjs.map +1 -1
  128. package/_cjs/Scope/Finalizer/definition.cjs +6 -4
  129. package/_cjs/Scope/Finalizer/definition.cjs.map +1 -1
  130. package/_cjs/Scope/Finalizer.cjs +1 -1
  131. package/_cjs/Scope/ReleaseMap/api/releaseAll.cjs +1 -1
  132. package/_cjs/Scope/ReleaseMap/api.cjs +1 -1
  133. package/_cjs/Scope/ReleaseMap/constructors.cjs +1 -1
  134. package/_cjs/Scope/ReleaseMap/definition.cjs +4 -2
  135. package/_cjs/Scope/ReleaseMap/definition.cjs.map +1 -1
  136. package/_cjs/Scope/ReleaseMap.cjs +3 -3
  137. package/_cjs/Scope/api.cjs +1 -1
  138. package/_cjs/Scope.cjs +2 -2
  139. package/_cjs/ScopedRef.cjs +2 -2
  140. package/_cjs/Sink/api.cjs +1 -1
  141. package/_cjs/Sink/api.cjs.map +1 -1
  142. package/_cjs/Sink.cjs +2 -2
  143. package/_cjs/State/api.cjs +2 -2
  144. package/_cjs/State/definition.cjs +1 -1
  145. package/_cjs/State.cjs +2 -2
  146. package/_cjs/Stream/api/zipAllWith.cjs +1 -1
  147. package/_cjs/Stream/api/zipWith.cjs +1 -1
  148. package/_cjs/Stream/api.cjs +308 -308
  149. package/_cjs/Stream/api.cjs.map +1 -1
  150. package/_cjs/Stream/internal/DebounceState.cjs.map +1 -1
  151. package/_cjs/Stream/internal/Handoff.cjs.map +1 -1
  152. package/_cjs/Stream/internal/SinkEndReason.cjs +2 -37
  153. package/_cjs/Stream/internal/SinkEndReason.cjs.map +1 -1
  154. package/_cjs/Stream.cjs +2 -2
  155. package/_cjs/Supervisor/constructors.cjs +1 -1
  156. package/_cjs/Supervisor.cjs +3 -3
  157. package/_cjs/TExit/constructors.cjs +1 -1
  158. package/_cjs/TExit.cjs +2 -2
  159. package/_cjs/TFuture/definition.cjs +4 -2
  160. package/_cjs/TFuture/definition.cjs.map +1 -1
  161. package/_cjs/TFuture.cjs +3 -3
  162. package/_cjs/TRef/api.cjs +2 -2
  163. package/_cjs/TRef/constructors.cjs +3 -3
  164. package/_cjs/TRef.cjs +3 -3
  165. package/_cjs/TSemaphore/api.cjs +1 -1
  166. package/_cjs/TSemaphore/definition.cjs +4 -2
  167. package/_cjs/TSemaphore/definition.cjs.map +1 -1
  168. package/_cjs/TSemaphore.cjs +3 -3
  169. package/_cjs/collection/immutable/Conc.cjs +3 -3
  170. package/_mjs/Channel/api/interruptWhen.mjs +1 -1
  171. package/_mjs/Channel/api/interruptWhen.mjs.map +1 -1
  172. package/_mjs/Channel/api/mapOutIOC.mjs +1 -1
  173. package/_mjs/Channel/api/mapOutIOC.mjs.map +1 -1
  174. package/_mjs/Channel/api/mergeAllWith.mjs +1 -1
  175. package/_mjs/Channel/api/mergeAllWith.mjs.map +1 -1
  176. package/_mjs/Channel/api/mergeWith.mjs +6 -6
  177. package/_mjs/Channel/api/mergeWith.mjs.map +1 -1
  178. package/_mjs/Channel/api.mjs +14 -14
  179. package/_mjs/Channel/api.mjs.map +1 -1
  180. package/_mjs/Channel/internal/ChannelExecutor.mjs +2 -2
  181. package/_mjs/Channel/internal/ChannelExecutor.mjs.map +1 -1
  182. package/_mjs/Channel/internal/SingleProducerAsyncInput.mjs +8 -7
  183. package/_mjs/Channel/internal/SingleProducerAsyncInput.mjs.map +1 -1
  184. package/_mjs/Clock/api.mjs.map +1 -1
  185. package/_mjs/Clock/live.mjs +1 -1
  186. package/_mjs/Clock/live.mjs.map +1 -1
  187. package/_mjs/Fiber/FiberContext.mjs +57 -56
  188. package/_mjs/Fiber/FiberContext.mjs.map +1 -1
  189. package/_mjs/Fiber/api/interruptFork.mjs +1 -1
  190. package/_mjs/Fiber/api/interruptFork.mjs.map +1 -1
  191. package/_mjs/FiberRef/constructors.mjs +1 -1
  192. package/_mjs/FiberRef/constructors.mjs.map +1 -1
  193. package/_mjs/FiberRefs/join.mjs +2 -2
  194. package/_mjs/FiberRefs/join.mjs.map +1 -1
  195. package/_mjs/IO/api/asyncIO.mjs +20 -0
  196. package/_mjs/IO/api/asyncIO.mjs.map +1 -0
  197. package/_mjs/IO/api/ensuringChildren.mjs +11 -0
  198. package/_mjs/IO/api/ensuringChildren.mjs.map +1 -0
  199. package/_mjs/IO/api/interrupt.mjs +4 -4
  200. package/_mjs/IO/api/interrupt.mjs.map +1 -1
  201. package/_mjs/IO/api/sleep.mjs.map +1 -1
  202. package/_mjs/IO/api/timeout.mjs +23 -0
  203. package/_mjs/IO/api/timeout.mjs.map +1 -0
  204. package/_mjs/IO/api.mjs +41 -40
  205. package/_mjs/IO/api.mjs.map +1 -1
  206. package/_mjs/IO/definition.mjs +6 -4
  207. package/_mjs/IO/definition.mjs.map +1 -1
  208. package/_mjs/IO/runtime.mjs +1 -1
  209. package/_mjs/IO/runtime.mjs.map +1 -1
  210. package/_mjs/IO.mjs +3 -0
  211. package/_mjs/IO.mjs.map +1 -1
  212. package/_mjs/Layer/api.mjs +4 -3
  213. package/_mjs/Layer/api.mjs.map +1 -1
  214. package/_mjs/Ref/Atomic/api.mjs +10 -6
  215. package/_mjs/Ref/Atomic/api.mjs.map +1 -1
  216. package/_mjs/Schedule/Decision.mjs.map +1 -1
  217. package/_mjs/Schedule/api/driver.mjs +10 -9
  218. package/_mjs/Schedule/api/driver.mjs.map +1 -1
  219. package/_mjs/Schedule/api.mjs +49 -49
  220. package/_mjs/Schedule/api.mjs.map +1 -1
  221. package/_mjs/Schedule.mjs +0 -1
  222. package/_mjs/Schedule.mjs.map +1 -1
  223. package/_mjs/Scope/Finalizer/definition.mjs +5 -4
  224. package/_mjs/Scope/Finalizer/definition.mjs.map +1 -1
  225. package/_mjs/Scope/ReleaseMap/definition.mjs +3 -2
  226. package/_mjs/Scope/ReleaseMap/definition.mjs.map +1 -1
  227. package/_mjs/Sink/api.mjs +1 -1
  228. package/_mjs/Sink/api.mjs.map +1 -1
  229. package/_mjs/Stream/api.mjs +308 -302
  230. package/_mjs/Stream/api.mjs.map +1 -1
  231. package/_mjs/Stream/internal/DebounceState.mjs.map +1 -1
  232. package/_mjs/Stream/internal/Handoff.mjs.map +1 -1
  233. package/_mjs/Stream/internal/SinkEndReason.mjs +1 -30
  234. package/_mjs/Stream/internal/SinkEndReason.mjs.map +1 -1
  235. package/_mjs/TFuture/definition.mjs +3 -2
  236. package/_mjs/TFuture/definition.mjs.map +1 -1
  237. package/_mjs/TSemaphore/definition.mjs +3 -2
  238. package/_mjs/TSemaphore/definition.mjs.map +1 -1
  239. package/_src/Channel/api.ts +3 -3
  240. package/_src/Channel/internal/ChannelExecutor.ts +2 -2
  241. package/_src/Channel/internal/SingleProducerAsyncInput.ts +1 -0
  242. package/_src/Clock/api.ts +1 -1
  243. package/_src/Clock/definition.ts +1 -1
  244. package/_src/Clock/live.ts +2 -2
  245. package/_src/Fiber/FiberContext.ts +3 -2
  246. package/_src/Fiber/api/interruptFork.ts +1 -1
  247. package/_src/FiberRef/constructors.ts +1 -1
  248. package/_src/FiberRefs/join.ts +2 -2
  249. package/_src/IO/api/asyncIO.ts +16 -0
  250. package/_src/IO/api/ensuringChildren.ts +11 -0
  251. package/_src/IO/api/interrupt.ts +2 -1
  252. package/_src/IO/api/sequenceT.ts +1 -1
  253. package/_src/IO/api/sleep.ts +1 -1
  254. package/_src/IO/api/timeout.ts +19 -0
  255. package/_src/IO/api.ts +6 -4
  256. package/_src/IO/definition.ts +8 -4
  257. package/_src/IO.ts +3 -0
  258. package/_src/Layer/api.ts +1 -1
  259. package/_src/Ref/Atomic/api.ts +4 -0
  260. package/_src/Schedule/Decision.ts +0 -2
  261. package/_src/Schedule/api/driver.ts +1 -1
  262. package/_src/Schedule/api.ts +0 -3
  263. package/_src/Schedule.ts +0 -1
  264. package/_src/Scope/Finalizer/definition.ts +1 -1
  265. package/_src/Scope/ReleaseMap/definition.ts +1 -1
  266. package/_src/Stream/api.ts +199 -134
  267. package/_src/Stream/internal/DebounceState.ts +2 -2
  268. package/_src/Stream/internal/Handoff.ts +9 -9
  269. package/_src/Stream/internal/SinkEndReason.ts +7 -25
  270. package/_src/TFuture/definition.ts +2 -2
  271. package/_src/TSemaphore/definition.ts +1 -1
  272. package/package.json +5 -5
  273. package/runTests.d.ts +1 -0
  274. package/Schedule/Interval.d.ts +0 -71
  275. package/_cjs/Schedule/Interval.cjs +0 -154
  276. package/_cjs/Schedule/Interval.cjs.map +0 -1
  277. package/_mjs/Schedule/Interval.mjs +0 -114
  278. package/_mjs/Schedule/Interval.mjs.map +0 -1
  279. package/_src/Schedule/Interval.ts +0 -103
@@ -7,6 +7,6 @@ import { identity, unsafeCoerce } from "@fncts/base/data/function";
7
7
  */
8
8
  export function sequenceT<T extends ReadonlyNonEmptyArray<IO<any, any, any>>>(
9
9
  ...ios: T
10
- ): IO<_R<T[number]>, _E<T[number]>, { [K in keyof T]: _A<T[K]> }> {
10
+ ): IO<HKT._R<T[number]>, HKT._E<T[number]>, { [K in keyof T]: HKT._A<T[K]> }> {
11
11
  return unsafeCoerce(IO.foreach(ios, identity));
12
12
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @tsplus static fncts.io.IOOps sleep
3
3
  */
4
- export function sleep(duration: number, __tsplusTrace?: string): UIO<void> {
4
+ export function sleep(duration: Lazy<Duration>, __tsplusTrace?: string): UIO<void> {
5
5
  return Clock.sleep(duration);
6
6
  }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @tsplus fluent fncts.io.IO timeoutTo
3
+ */
4
+ export function timeoutTo<R, E, A, B, B1>(
5
+ self: IO<R, E, A>,
6
+ duration: Lazy<Duration>,
7
+ b: Lazy<B>,
8
+ f: (a: A) => B1,
9
+ __tsplusTrace?: string,
10
+ ): IO<R, E, B | B1> {
11
+ return self.map(f).raceFirst(IO.sleep(duration).interruptible.as(b));
12
+ }
13
+
14
+ /**
15
+ * @tsplus fluent fncts.io.IO timeout
16
+ */
17
+ export function timeout<R, E, A>(self: IO<R, E, A>, duration: Lazy<Duration>): IO<R, E, Maybe<A>> {
18
+ return self.timeoutTo(duration, Nothing(), Maybe.just);
19
+ }
package/_src/IO/api.ts CHANGED
@@ -761,12 +761,14 @@ export function foldLeft_<A, B, R, E>(
761
761
  /**
762
762
  * Combines an array of `IO`s using a `Monoid`
763
763
  *
764
- * @constrained
765
764
  * @tsplus static fncts.io.IOOps foldMap
766
765
  */
767
- export function foldMap_<M>(M: P.Monoid<M>) {
768
- return <R, E, A>(as: Iterable<IO<R, E, A>>, f: (a: A) => M): IO<R, E, M> =>
769
- IO.foldLeft(as, M.nat, (m, a) => a.map((a) => M.combine_(m, f(a))));
766
+ export function foldMap_<R, E, A, M>(
767
+ as: Iterable<IO<R, E, A>>,
768
+ f: (a: A) => M,
769
+ /** @tsplus auto */ M: P.Monoid<M>,
770
+ ): IO<R, E, M> {
771
+ return IO.foldLeft(as, M.nat, (m, a) => a.map((a) => M.combine(m, f(a))));
770
772
  }
771
773
 
772
774
  function foldRightLoop<A, B, R, E>(
@@ -4,15 +4,19 @@ import type { FiberContext } from "@fncts/io/Fiber/FiberContext";
4
4
  export const IOTypeId = Symbol.for("fncts.io.IO");
5
5
  export type IOTypeId = typeof IOTypeId;
6
6
 
7
+ export interface IOF extends IO<any, any, any> {}
8
+
7
9
  /**
8
10
  * @tsplus type fncts.io.IO
9
11
  * @tsplus companion fncts.io.IOOps
10
12
  */
11
13
  export abstract class IO<R, E, A> {
12
14
  readonly _typeId: IOTypeId = IOTypeId;
13
- readonly _R!: (_: R) => void;
14
- readonly _E!: () => E;
15
- readonly _A!: () => A;
15
+ readonly [HKT.F]!: IOF;
16
+ readonly [HKT.R]!: (_: R) => void;
17
+ readonly [HKT.E]!: () => E;
18
+ readonly [HKT.A]!: () => A;
19
+ readonly [HKT.T]!: IO<HKT._R<this>, HKT._E<this>, HKT._A<this>>;
16
20
  }
17
21
 
18
22
  /**
@@ -407,7 +411,7 @@ export type Instruction =
407
411
  | SetRuntimeConfig;
408
412
 
409
413
  /**
410
- * @optimize identity
414
+ * @tsplus macro identity
411
415
  */
412
416
  export function concrete(_: IO<any, any, any>): Instruction {
413
417
  // @ts-expect-error
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/asyncIO.js";
14
15
  export * from "./IO/api/bracket.js";
15
16
  export * from "./IO/api/bracketExit.js";
16
17
  export * from "./IO/api/clockWith.js";
@@ -18,6 +19,7 @@ export * from "./IO/api/concurrency.js";
18
19
  export * from "./IO/api/concurrentFinalizers.js";
19
20
  export * from "./IO/api/consoleWith.js";
20
21
  export * from "./IO/api/core-scope.js";
22
+ export * from "./IO/api/ensuringChildren.js";
21
23
  export * from "./IO/api/environment.js";
22
24
  export * from "./IO/api/foreachC.js";
23
25
  export * from "./IO/api/foreachExec.js";
@@ -43,6 +45,7 @@ export * from "./IO/api/scopeWith.js";
43
45
  export * from "./IO/api/sequenceT.js";
44
46
  export * from "./IO/api/sleep.js";
45
47
  export * from "./IO/api/stateful.js";
48
+ export * from "./IO/api/timeout.js";
46
49
  export * from "./IO/api/withChildren.js";
47
50
  export * from "./IO/api/withFinalizer.js";
48
51
  export * from "./IO/api/withFinalizerExit.js";
package/_src/Layer/api.ts CHANGED
@@ -282,7 +282,7 @@ function retryUpdate<S, RIn, E, X>(
282
282
  .flatMap(([state, _, decision]) =>
283
283
  decision._tag === DecisionTag.Done
284
284
  ? IO.failNow(e)
285
- : Clock.sleep(decision.interval.startMilliseconds - now).as({ state }),
285
+ : Clock.sleep(Duration.fromInterval(now, decision.interval.startMilliseconds)).as({ state }),
286
286
  ),
287
287
  ),
288
288
  tag,
@@ -29,6 +29,7 @@ export function getAndUpdateJust<A>(self: Atomic<A>, f: (a: A) => Maybe<A>) {
29
29
  return IO.succeed(() => {
30
30
  const v = self.unsafeGet;
31
31
  const o = f(v);
32
+ Maybe.concrete(o);
32
33
  if (o._tag === "Just") {
33
34
  self.unsafeSet(o.value);
34
35
  }
@@ -56,6 +57,7 @@ export function modifyJust<A, B>(self: Atomic<A>, def: B, f: (a: A) => Maybe<rea
56
57
  const v = self.unsafeGet;
57
58
  const o = f(v);
58
59
 
60
+ Maybe.concrete(o);
59
61
  if (o._tag === "Just") {
60
62
  self.unsafeSet(o.value[1]);
61
63
  return o.value[0];
@@ -91,6 +93,7 @@ export function updateJust<A>(self: Atomic<A>, f: (a: A) => Maybe<A>) {
91
93
  return IO.succeed(() => {
92
94
  const o = f(self.unsafeGet);
93
95
 
96
+ Maybe.concrete(o);
94
97
  if (o._tag === "Just") {
95
98
  self.unsafeSet(o.value);
96
99
  }
@@ -104,6 +107,7 @@ export function updateJustAndGet<A>(self: Atomic<A>, f: (a: A) => Maybe<A>) {
104
107
  return IO.succeed(() => {
105
108
  const o = f(self.unsafeGet);
106
109
 
110
+ Maybe.concrete(o);
107
111
  if (o._tag === "Just") {
108
112
  self.unsafeSet(o.value);
109
113
  }
@@ -1,5 +1,3 @@
1
- import type { Interval } from "./Interval.js";
2
-
3
1
  export const enum DecisionTag {
4
2
  Continue = "Continue",
5
3
  Done = "Done",
@@ -19,7 +19,7 @@ export function driver<State, Env, In, Out>(
19
19
  (interval) =>
20
20
  ref
21
21
  .set([Just(out), state1])
22
- .apSecond(Clock.sleep(interval.startMilliseconds - now))
22
+ .apSecond(Clock.sleep(Duration.fromInterval(now, interval.startMilliseconds)))
23
23
  .as(out),
24
24
  ),
25
25
  );
@@ -1,7 +1,4 @@
1
- import { Driver } from "@fncts/io/Schedule/Driver";
2
-
3
1
  import { Decision, DecisionTag } from "./Decision.js";
4
- import { Interval } from "./Interval.js";
5
2
 
6
3
  /**
7
4
  * @tsplus static fncts.io.ScheduleOps __call
package/_src/Schedule.ts CHANGED
@@ -3,5 +3,4 @@ export * from "./Schedule/api.js";
3
3
  export * from "./Schedule/Decision.js";
4
4
  export * from "./Schedule/definition.js";
5
5
  export * from "./Schedule/Driver.js";
6
- export * from "./Schedule/Interval.js";
7
6
  // codegen:end
@@ -1,5 +1,5 @@
1
1
  interface FinalizerN extends HKT {
2
- readonly type: Finalizer;
2
+ readonly [HKT.T]: Finalizer;
3
3
  }
4
4
 
5
5
  /**
@@ -15,7 +15,7 @@ export class Running {
15
15
  export type State = Exited | Running;
16
16
 
17
17
  interface ReleaseMapN extends HKT {
18
- readonly type: ReleaseMap;
18
+ readonly [HKT.T]: ReleaseMap;
19
19
  }
20
20
 
21
21
  /**
@@ -12,7 +12,8 @@ import { DEFAULT_CHUNK_SIZE, Stream } from "./definition.js";
12
12
  import { DebounceState } from "./internal/DebounceState.js";
13
13
  import { Handoff, HandoffSignal } from "./internal/Handoff.js";
14
14
  import { Pull } from "./internal/Pull.js";
15
- import { ScheduleEnd, ScheduleTimeout, SinkEnd, UpstreamEnd } from "./internal/SinkEndReason.js";
15
+ import { SinkEndReasonTag } from "./internal/SinkEndReason.js";
16
+ import { ScheduleEnd, UpstreamEnd } from "./internal/SinkEndReason.js";
16
17
  import { Take } from "./internal/Take.js";
17
18
 
18
19
  /**
@@ -77,17 +78,17 @@ export function aggregateAsyncWithinEither_<R, E, A extends A1, R1, E1, A1, B, R
77
78
  sink: Sink<R1, E1, A1, A1, B>,
78
79
  schedule: Schedule<R2, Maybe<B>, C>,
79
80
  ): Stream<R & R1 & R2, E | E1, Either<C, B>> {
80
- type LocalHandoffSignal = HandoffSignal<C, E | E1, A1>;
81
- type LocalSinkEndReason = SinkEndReason<C>;
81
+ type LocalHandoffSignal = HandoffSignal<E | E1, A1>;
82
82
 
83
83
  const deps = IO.sequenceT(
84
84
  Handoff<LocalHandoffSignal>(),
85
- Ref.make<LocalSinkEndReason>(new SinkEnd()),
85
+ Ref.make<SinkEndReason>(new ScheduleEnd()),
86
86
  Ref.make(Conc.empty<A1>()),
87
87
  schedule.driver,
88
+ Ref.make(false),
88
89
  );
89
90
 
90
- return Stream.fromIO(deps).flatMap(([handoff, sinkEndReason, sinkLeftovers, scheduleDriver]) => {
91
+ return Stream.fromIO(deps).flatMap(([handoff, sinkEndReason, sinkLeftovers, scheduleDriver, consumed]) => {
91
92
  const handoffProducer: Channel<unknown, E | E1, Conc<A1>, unknown, never, never, any> = Channel.readWithCause(
92
93
  (_in: Conc<A1>) => Channel.fromIO(handoff.offer(HandoffSignal.Emit(_in))).apSecond(handoffProducer),
93
94
  (cause: Cause<E | E1>) => Channel.fromIO(handoff.offer(HandoffSignal.Halt(cause))),
@@ -96,62 +97,102 @@ export function aggregateAsyncWithinEither_<R, E, A extends A1, R1, E1, A1, B, R
96
97
 
97
98
  const handoffConsumer: Channel<unknown, unknown, unknown, unknown, E | E1, Conc<A1>, void> = Channel.unwrap(
98
99
  sinkLeftovers.getAndSet(Conc.empty<A>()).flatMap((leftovers) => {
99
- if (leftovers.isEmpty) {
100
- return IO.succeedNow(Channel.writeNow(leftovers).apSecond(handoffConsumer));
100
+ if (leftovers.isNonEmpty) {
101
+ return consumed.set(true) > IO.succeedNow(Channel.writeNow(leftovers) > handoffConsumer);
101
102
  } else {
102
103
  return handoff.take.map((signal) =>
103
104
  signal.match({
104
- Emit: ({ els }) => Channel.writeNow(els).apSecond(handoffConsumer),
105
+ Emit: ({ els }) => Channel.fromIO(consumed.set(true)) > Channel.writeNow(els) > handoffConsumer,
105
106
  Halt: ({ error }) => Channel.failCause(error),
106
- End: ({ reason }) => Channel.fromIO(sinkEndReason.set(reason)),
107
+ End: ({ reason }) => {
108
+ if (reason._tag === SinkEndReasonTag.ScheduleEnd) {
109
+ return Channel.unwrap(
110
+ consumed.get.map((p) =>
111
+ p
112
+ ? Channel.fromIO(sinkEndReason.set(new ScheduleEnd()))
113
+ : Channel.fromIO(sinkEndReason.set(new ScheduleEnd())) > handoffConsumer,
114
+ ),
115
+ );
116
+ } else {
117
+ return Channel.fromIO(sinkEndReason.set(reason));
118
+ }
119
+ },
107
120
  }),
108
121
  );
109
122
  }
110
123
  }),
111
124
  );
112
125
 
126
+ function timeout(lastB: Maybe<B>): IO<R2, Nothing, C> {
127
+ return scheduleDriver.next(lastB);
128
+ }
129
+
113
130
  const scheduledAggregator = (
114
- lastB: Maybe<B>,
131
+ sinkFiber: Fiber.Runtime<E | E1, readonly [Conc<Conc<A1>>, B]>,
132
+ scheduleFiber: Fiber.Runtime<Nothing, C>,
115
133
  ): Channel<R1 & R2, unknown, unknown, unknown, E | E1, Conc<Either<C, B>>, any> => {
116
- const timeout = scheduleDriver.next(lastB).matchCauseIO(
117
- (_) =>
118
- _.failureOrCause.match(
119
- () => handoff.offer(HandoffSignal.End(new ScheduleTimeout())),
120
- (cause) => handoff.offer(HandoffSignal.Halt(cause)),
121
- ),
122
- (c) => handoff.offer(HandoffSignal.End(new ScheduleEnd(c))),
123
- );
134
+ const forkSink =
135
+ consumed.set(false) > handoffConsumer.pipeToOrFail(sink.channel).doneCollect.runScoped.forkScoped;
136
+
137
+ function handleSide(leftovers: Conc<Conc<A1>>, b: B, c: Maybe<C>) {
138
+ return Channel.unwrap(
139
+ sinkLeftovers.set(leftovers.flatten) >
140
+ sinkEndReason.get.map((reason) =>
141
+ reason.match({
142
+ ScheduleEnd: () =>
143
+ Channel.unwrapScoped(
144
+ Do((Δ) => {
145
+ const consumed_ = Δ(consumed.get);
146
+ const sinkFiber = Δ(forkSink);
147
+ const scheduleFiber = Δ(timeout(Just(b)).forkScoped);
148
+ const toWrite = c.match(
149
+ () => Conc(Either.right(b)),
150
+ (c) => Conc(Either.right(b), Either.left(c)),
151
+ );
152
+ return consumed_
153
+ ? Channel.write(toWrite) > scheduledAggregator(sinkFiber, scheduleFiber)
154
+ : scheduledAggregator(sinkFiber, scheduleFiber);
155
+ }),
156
+ ),
157
+ UpstreamEnd: () =>
158
+ Channel.unwrap(consumed.get.map((p) => (p ? Channel.write(Conc(Either.right(b))) : Channel.unit))),
159
+ }),
160
+ ),
161
+ );
162
+ }
124
163
 
125
- return Channel.unwrapScoped(
126
- timeout.forkScoped.map((fiber) => {
127
- return handoffConsumer.pipeToOrFail(sink.channel).doneCollect.flatMap(([leftovers, b]) => {
128
- return Channel.fromIO(fiber.interrupt.apSecond(sinkLeftovers.set(leftovers.flatten))).apSecond(
129
- Channel.unwrap(
130
- sinkEndReason.modify((reason) =>
131
- reason.match({
132
- ScheduleEnd: ({ c }) =>
133
- tuple(Channel.writeNow(Conc.from([Either.right(b), Either.left(c)])).as(Just(b)), new SinkEnd()),
134
- ScheduleTimeout: () =>
135
- tuple(Channel.writeNow(Conc.single(Either.right(b))).as(Just(b)), new SinkEnd()),
136
- SinkEnd: () => tuple(Channel.writeNow(Conc.single(Either.right(b))).as(Just(b)), new SinkEnd()),
137
- UpstreamEnd: () =>
138
- tuple(Channel.writeNow(Conc.single(Either.right(b))).as(Nothing()), new UpstreamEnd()),
139
- }),
164
+ return Channel.unwrap(
165
+ sinkFiber.join.raceWith(
166
+ scheduleFiber.join,
167
+ (sinkExit, scheduleFiber) =>
168
+ scheduleFiber.interrupt >
169
+ IO.fromExit(sinkExit).map(([leftovers, b]) => handleSide(leftovers, b, Nothing())),
170
+ (scheduleExit, sinkFiber) =>
171
+ IO.fromExit(scheduleExit).matchCauseIO(
172
+ (cause) =>
173
+ cause.failureOrCause.match(
174
+ () =>
175
+ handoff.offer(HandoffSignal.End(new ScheduleEnd())).forkDaemon >
176
+ sinkFiber.join.map(([leftovers, b]) => handleSide(leftovers, b, Nothing())),
177
+ (cause) =>
178
+ handoff.offer(HandoffSignal.Halt(cause)).forkDaemon >
179
+ sinkFiber.join.map(([leftovers, b]) => handleSide(leftovers, b, Nothing())),
140
180
  ),
141
- ),
142
- );
143
- });
144
- }),
145
- ).flatMap((_) =>
146
- _.match(
147
- () => Channel.unit,
148
- () => scheduledAggregator(_),
181
+ (c) =>
182
+ handoff.offer(HandoffSignal.End(new ScheduleEnd())).forkDaemon >
183
+ sinkFiber.join.map(([leftovers, b]) => handleSide(leftovers, b, Just(c))),
184
+ ),
149
185
  ),
150
186
  );
151
187
  };
152
188
 
153
- return Stream.scoped(stream.channel.pipeTo(handoffProducer).runScoped.forkDaemon).apSecond(
154
- new Stream(scheduledAggregator(Nothing())),
189
+ return Stream.unwrapScoped(
190
+ Do((Δ) => {
191
+ Δ(stream.channel.pipeTo(handoffProducer).runScoped.forkScoped);
192
+ const sinkFiber = Δ(handoffConsumer.pipeToOrFail(sink.channel).doneCollect.runScoped.forkScoped);
193
+ const scheduleFiber = Δ(timeout(Nothing()).forkScoped);
194
+ return new Stream(scheduledAggregator(sinkFiber, scheduleFiber));
195
+ }),
155
196
  );
156
197
  });
157
198
  }
@@ -669,23 +710,28 @@ export function collectWhileIO_<R, E, A, R1, E1, B>(
669
710
  stream: Stream<R, E, A>,
670
711
  pf: (a: A) => Maybe<IO<R1, E1, B>>,
671
712
  ): Stream<R & R1, E | E1, B> {
672
- return stream.loopOnPartialChunks((chunk, emit) => {
673
- const pfJust = (a: A) =>
674
- pf(a).match(
675
- () => IO.succeedNow(false),
676
- (effect) => effect.flatMap(emit).as(true),
677
- );
678
-
679
- const loop = (chunk: Conc<A>): IO<R1, E1, boolean> => {
680
- if (chunk.isEmpty) {
681
- return IO.succeedNow(true);
682
- } else {
683
- return pfJust(chunk.unsafeHead).flatMap((cont) => (cont ? loop(chunk.unsafeTail) : IO.succeedNow(false)));
684
- }
685
- };
713
+ return new Stream(stream.channel.pipeTo(collectWhileIOLoop(Iterable.empty<A>()[Symbol.iterator](), pf)));
714
+ }
686
715
 
687
- return loop(chunk);
688
- });
716
+ function collectWhileIOLoop<R, E, A, R1, E1, B>(
717
+ iterator: Iterator<A>,
718
+ pf: (a: A) => Maybe<IO<R1, E1, B>>,
719
+ ): Channel<R & R1, E, Conc<A>, unknown, E | E1, Conc<B>, unknown> {
720
+ const next = iterator.next();
721
+ if (next.done) {
722
+ return Channel.readWithCause(
723
+ (elem) => collectWhileIOLoop(elem[Symbol.iterator](), pf),
724
+ Channel.failCauseNow,
725
+ Channel.succeedNow,
726
+ );
727
+ } else {
728
+ return Channel.unwrap(
729
+ pf(next.value).match(
730
+ () => IO.succeedNow(Channel.unit),
731
+ (b) => b.map((b) => Channel.writeNow(Conc.single(b)) > collectWhileIOLoop<R, E, A, R1, E1, B>(iterator, pf)),
732
+ ),
733
+ );
734
+ }
689
735
  }
690
736
 
691
737
  function combineProducer<Err, Elem>(
@@ -857,11 +903,11 @@ export function contramapEnvironment_<R, E, A, R0>(
857
903
  /**
858
904
  * @tsplus fluent fncts.io.Stream debounce
859
905
  */
860
- export function debounce_<R, E, A>(stream: Stream<R, E, A>, duration: number): Stream<R, E, A> {
906
+ export function debounce_<R, E, A>(stream: Stream<R, E, A>, duration: Lazy<Duration>): Stream<R, E, A> {
861
907
  return Stream.unwrap(
862
908
  IO.transplant((grafter) =>
863
909
  Do((Δ) => {
864
- const handoff = Δ(Handoff<HandoffSignal<void, E, A>>());
910
+ const handoff = Δ(Handoff<HandoffSignal<E, A>>());
865
911
  function enqueue(last: Conc<A>) {
866
912
  return grafter(Clock.sleep(duration).as(last).fork).map((f) => consumer(DebounceState.Previous(f)));
867
913
  }
@@ -1274,7 +1320,29 @@ export function filterIO_<R, E, A, R1, E1>(
1274
1320
  fa: Stream<R, E, A>,
1275
1321
  f: (a: A) => IO<R1, E1, boolean>,
1276
1322
  ): Stream<R & R1, E | E1, A> {
1277
- return fa.loopOnPartialChunksElements((a, emit) => f(a).flatMap((r) => (r ? emit(a) : IO.unit)));
1323
+ return new Stream(fa.channel.pipeTo(filterIOLoop(Iterable.empty<A>()[Symbol.iterator](), f)));
1324
+ }
1325
+
1326
+ function filterIOLoop<R, E, A, R1, E1>(
1327
+ iterator: Iterator<A>,
1328
+ f: (a: A) => IO<R1, E1, boolean>,
1329
+ ): Channel<R & R1, E, Conc<A>, unknown, E | E1, Conc<A>, unknown> {
1330
+ const next = iterator.next();
1331
+ if (next.done) {
1332
+ return Channel.readWithCause(
1333
+ (elem) => filterIOLoop(elem[Symbol.iterator](), f),
1334
+ Channel.failCauseNow,
1335
+ Channel.succeedNow,
1336
+ );
1337
+ } else {
1338
+ return Channel.unwrap(
1339
+ f(next.value).map((b) =>
1340
+ b
1341
+ ? Channel.writeNow(Conc.single(next.value)) > filterIOLoop<R, E, A, R1, E1>(iterator, f)
1342
+ : filterIOLoop<R, E, A, R1, E1>(iterator, f),
1343
+ ),
1344
+ );
1345
+ }
1278
1346
  }
1279
1347
 
1280
1348
  /**
@@ -1291,7 +1359,30 @@ export function filterMapIO_<R, E, A, R1, E1, B>(
1291
1359
  fa: Stream<R, E, A>,
1292
1360
  f: (a: A) => IO<R1, E1, Maybe<B>>,
1293
1361
  ): Stream<R & R1, E | E1, B> {
1294
- return fa.loopOnPartialChunksElements((a, emit) => f(a).flatMap((maybeB) => maybeB.match(() => IO.unit, emit)));
1362
+ return new Stream(fa.channel.pipeTo(filterMapIOLoop<R, E, A, R1, E1, B>(Iterable.empty<A>()[Symbol.iterator](), f)));
1363
+ }
1364
+
1365
+ function filterMapIOLoop<R, E, A, R1, E1, B>(
1366
+ iterator: Iterator<A>,
1367
+ f: (a: A) => IO<R1, E1, Maybe<B>>,
1368
+ ): Channel<R & R1, E, Conc<A>, unknown, E | E1, Conc<B>, unknown> {
1369
+ const next = iterator.next();
1370
+ if (next.done) {
1371
+ return Channel.readWithCause(
1372
+ (elem) => filterMapIOLoop(elem[Symbol.iterator](), f),
1373
+ Channel.failCauseNow,
1374
+ Channel.succeedNow,
1375
+ );
1376
+ } else {
1377
+ return Channel.unwrap(
1378
+ f(next.value).map((b) =>
1379
+ b.match(
1380
+ () => filterMapIOLoop(iterator, f),
1381
+ (b) => Channel.writeNow(Conc.single(b)) > filterMapIOLoop<R, E, A, R1, E1, B>(iterator, f),
1382
+ ),
1383
+ ),
1384
+ );
1385
+ }
1295
1386
  }
1296
1387
 
1297
1388
  /**
@@ -1788,68 +1879,6 @@ export function interruptWhenFuture_<R, E, A, E1>(
1788
1879
  return new Stream(fa.channel.interruptWhen(future));
1789
1880
  }
1790
1881
 
1791
- /**
1792
- * Loops over the stream chunks concatenating the result of f
1793
- *
1794
- * @tsplus fluent fncts.io.Stream loopOnChunks
1795
- */
1796
- export function loopOnChunks_<R, E, A, R1, E1, A1>(
1797
- stream: Stream<R, E, A>,
1798
- f: (a: Conc<A>) => Channel<R1, E | E1, Conc<A>, unknown, E | E1, Conc<A1>, boolean>,
1799
- ): Stream<R & R1, E | E1, A1> {
1800
- const loop: Channel<R1, E | E1, Conc<A>, unknown, E | E1, Conc<A1>, boolean> = Channel.readWithCause(
1801
- (chunk) => f(chunk).flatMap((cont) => (cont ? loop : Channel.endNow(false))),
1802
- Channel.failCauseNow,
1803
- (_) => Channel.succeedNow(false),
1804
- );
1805
- return new Stream(stream.channel.pipeTo(loop));
1806
- }
1807
-
1808
- /**
1809
- * Loops on chunks emitting partially
1810
- *
1811
- * @tsplus fluent fncts.io.Stream loopOnPartialChunks
1812
- */
1813
- export function loopOnPartialChunks_<R, E, A, R1, E1, A1>(
1814
- stream: Stream<R, E, A>,
1815
- f: (a: Conc<A>, emit: (a: A1) => UIO<void>) => IO<R1, E1, boolean>,
1816
- ): Stream<R & R1, E | E1, A1> {
1817
- return stream.loopOnChunks((chunk) =>
1818
- Channel.unwrap(
1819
- IO.defer(() => {
1820
- let outputChunk = Conc.empty<A1>();
1821
- return f(chunk, (a) =>
1822
- IO.succeed(() => {
1823
- outputChunk = outputChunk.append(a);
1824
- }),
1825
- )
1826
- .map((cont) => Channel.write(outputChunk).apSecond(Channel.endNow(cont)))
1827
- .catchAll((failure) =>
1828
- IO.succeed(() => {
1829
- if (outputChunk.isEmpty) {
1830
- return Channel.failNow(failure);
1831
- } else {
1832
- return Channel.writeNow(outputChunk).apSecond(Channel.failNow(failure));
1833
- }
1834
- }),
1835
- );
1836
- }),
1837
- ),
1838
- );
1839
- }
1840
-
1841
- /**
1842
- * Loops on chunks elements emitting partially
1843
- *
1844
- * @tsplus fluent fncts.io.Stream loopOnPartialChunksElements
1845
- */
1846
- export function loopOnPartialChunksElements_<R, E, A, R1, E1, A1>(
1847
- stream: Stream<R, E, A>,
1848
- f: (a: A, emit: (a: A1) => UIO<void>) => IO<R1, E1, void>,
1849
- ): Stream<R & R1, E | E1, A1> {
1850
- return stream.loopOnPartialChunks((as, emit) => as.mapIO((a) => f(a, emit)).as(true));
1851
- }
1852
-
1853
1882
  /**
1854
1883
  * Transforms the elements of this stream using the supplied function.
1855
1884
  *
@@ -1861,11 +1890,11 @@ export function map_<R, E, A, B>(stream: Stream<R, E, A>, f: (o: A) => B): Strea
1861
1890
 
1862
1891
  function mapAccumAccumulator<S, E = never, A = never, B = never>(
1863
1892
  currS: S,
1864
- f: (s: S, a: A) => readonly [B, S],
1893
+ f: (s: S, a: A) => readonly [S, B],
1865
1894
  ): Channel<unknown, E, Conc<A>, unknown, E, Conc<B>, void> {
1866
1895
  return Channel.readWith(
1867
1896
  (inp: Conc<A>) => {
1868
- const [bs, nextS] = inp.mapAccum(currS, f);
1897
+ const [nextS, bs] = inp.mapAccum(currS, f);
1869
1898
  return Channel.writeNow(bs).apSecond(mapAccumAccumulator(nextS, f));
1870
1899
  },
1871
1900
  Channel.failNow,
@@ -1881,7 +1910,7 @@ function mapAccumAccumulator<S, E = never, A = never, B = never>(
1881
1910
  export function mapAccum_<R, E, A, S, B>(
1882
1911
  stream: Stream<R, E, A>,
1883
1912
  s: S,
1884
- f: (s: S, a: A) => readonly [B, S],
1913
+ f: (s: S, a: A) => readonly [S, B],
1885
1914
  ): Stream<R, E, B> {
1886
1915
  return new Stream(stream.channel.pipeTo(mapAccumAccumulator(s, f)));
1887
1916
  }
@@ -2023,7 +2052,25 @@ export function mapIO_<R, E, A, R1, E1, B>(
2023
2052
  stream: Stream<R, E, A>,
2024
2053
  f: (a: A) => IO<R1, E1, B>,
2025
2054
  ): Stream<R & R1, E | E1, B> {
2026
- return stream.loopOnPartialChunksElements((a, emit) => f(a).flatMap(emit));
2055
+ return new Stream(stream.channel.pipeTo(mapIOLoop(Iterable.empty<A>()[Symbol.iterator](), f)));
2056
+ }
2057
+
2058
+ function mapIOLoop<R, E, A, R1, E1, B>(
2059
+ iterator: Iterator<A>,
2060
+ f: (a: A) => IO<R1, E1, B>,
2061
+ ): Channel<R & R1, E, Conc<A>, unknown, E | E1, Conc<B>, unknown> {
2062
+ const next = iterator.next();
2063
+ if (next.done) {
2064
+ return Channel.readWithCause(
2065
+ (elem) => mapIOLoop(elem[Symbol.iterator](), f),
2066
+ Channel.failCauseNow,
2067
+ Channel.succeedNow,
2068
+ );
2069
+ } else {
2070
+ return Channel.unwrap(
2071
+ f(next.value).map((b) => Channel.writeNow(Conc.single(b)) > mapIOLoop<R, E, A, R1, E1, B>(iterator, f)),
2072
+ );
2073
+ }
2027
2074
  }
2028
2075
 
2029
2076
  /**
@@ -2582,11 +2629,29 @@ export function takeUntilIO_<R, E, A, R1, E1>(
2582
2629
  ma: Stream<R, E, A>,
2583
2630
  f: (a: A) => IO<R1, E1, boolean>,
2584
2631
  ): Stream<R & R1, E | E1, A> {
2585
- return ma.loopOnPartialChunks((chunk, emit) =>
2586
- chunk
2587
- .takeWhileIO((v) => emit(v).apSecond(f(v).map((b) => !b)))
2588
- .map((taken) => taken.drop(taken.length).take(1).isEmpty),
2589
- );
2632
+ return new Stream(ma.channel.pipeTo(takeUntilIOLoop(Iterable.empty<A>()[Symbol.iterator](), f)));
2633
+ }
2634
+
2635
+ function takeUntilIOLoop<R, E, A, R1, E1>(
2636
+ iterator: Iterator<A>,
2637
+ f: (a: A) => IO<R1, E1, boolean>,
2638
+ ): Channel<R & R1, E, Conc<A>, unknown, E | E1, Conc<A>, unknown> {
2639
+ const next = iterator.next();
2640
+ if (next.done) {
2641
+ return Channel.readWithCause(
2642
+ (elem) => takeUntilIOLoop(elem[Symbol.iterator](), f),
2643
+ Channel.failCauseNow,
2644
+ Channel.succeedNow,
2645
+ );
2646
+ } else {
2647
+ return Channel.unwrap(
2648
+ f(next.value).map((b) =>
2649
+ b
2650
+ ? Channel.writeNow(Conc.single(next.value))
2651
+ : Channel.writeNow(Conc.single(next.value)) > takeUntilIOLoop<R, E, A, R1, E1>(iterator, f),
2652
+ ),
2653
+ );
2654
+ }
2590
2655
  }
2591
2656
 
2592
2657
  function takeUntilLoop<R, E, A>(p: Predicate<A>): Channel<R, E, Conc<A>, unknown, E, Conc<A>, unknown> {