@fncts/io 0.0.8 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (267) hide show
  1. package/Channel/api.d.ts +27 -4
  2. package/Channel/internal/MergeDecision.d.ts +14 -0
  3. package/IO/api/onTermination.d.ts +9 -0
  4. package/IO.d.ts +1 -0
  5. package/STM/api.d.ts +7 -0
  6. package/Sink/api.d.ts +637 -8
  7. package/TReentrantLock/api.d.ts +97 -0
  8. package/TReentrantLock/definition.d.ts +65 -0
  9. package/TReentrantLock.d.ts +2 -0
  10. package/_cjs/Cached/api.cjs +5 -5
  11. package/_cjs/Cached/api.cjs.map +1 -1
  12. package/_cjs/Channel/api/mapOutIOC.cjs +9 -9
  13. package/_cjs/Channel/api/mapOutIOC.cjs.map +1 -1
  14. package/_cjs/Channel/api/mergeAllWith.cjs +18 -18
  15. package/_cjs/Channel/api/mergeAllWith.cjs.map +1 -1
  16. package/_cjs/Channel/api/mergeWith.cjs +5 -5
  17. package/_cjs/Channel/api/mergeWith.cjs.map +1 -1
  18. package/_cjs/Channel/api/run.cjs +3 -3
  19. package/_cjs/Channel/api/runCollect.cjs +3 -3
  20. package/_cjs/Channel/api/runDrain.cjs +3 -3
  21. package/_cjs/Channel/api.cjs +90 -35
  22. package/_cjs/Channel/api.cjs.map +1 -1
  23. package/_cjs/Channel/internal/ChannelExecutor.cjs +16 -16
  24. package/_cjs/Channel/internal/ChannelExecutor.cjs.map +1 -1
  25. package/_cjs/Channel/internal/MergeDecision.cjs +11 -2
  26. package/_cjs/Channel/internal/MergeDecision.cjs.map +1 -1
  27. package/_cjs/Channel/internal/SingleProducerAsyncInput.cjs +20 -20
  28. package/_cjs/Channel/internal/SingleProducerAsyncInput.cjs.map +1 -1
  29. package/_cjs/Fiber/api/awaitAll.cjs +1 -1
  30. package/_cjs/Fiber/api/awaitAll.cjs.map +1 -1
  31. package/_cjs/Fiber/api/fromIO.cjs +1 -1
  32. package/_cjs/Fiber/api/fromIO.cjs.map +1 -1
  33. package/_cjs/Fiber/api/interruptFork.cjs +3 -3
  34. package/_cjs/Fiber/api/interruptFork.cjs.map +1 -1
  35. package/_cjs/Fiber/api/zipWith.cjs +1 -1
  36. package/_cjs/Fiber/api/zipWith.cjs.map +1 -1
  37. package/_cjs/FiberRef/api/locallyScoped.cjs +3 -3
  38. package/_cjs/FiberRef/api/locallyScoped.cjs.map +1 -1
  39. package/_cjs/FiberRef/constructors.cjs +1 -1
  40. package/_cjs/FiberRef/constructors.cjs.map +1 -1
  41. package/_cjs/Future/api.cjs +1 -1
  42. package/_cjs/Future/api.cjs.map +1 -1
  43. package/_cjs/Hub/internal.cjs +1 -1
  44. package/_cjs/Hub/internal.cjs.map +1 -1
  45. package/_cjs/IO/api/asyncIO.cjs +4 -4
  46. package/_cjs/IO/api/asyncIO.cjs.map +1 -1
  47. package/_cjs/IO/api/bracketExit.cjs +1 -1
  48. package/_cjs/IO/api/bracketExit.cjs.map +1 -1
  49. package/_cjs/IO/api/environment.cjs +5 -5
  50. package/_cjs/IO/api/environment.cjs.map +1 -1
  51. package/_cjs/IO/api/foreachC.cjs +3 -3
  52. package/_cjs/IO/api/foreachC.cjs.map +1 -1
  53. package/_cjs/IO/api/foreachExec.cjs +3 -3
  54. package/_cjs/IO/api/foreachExec.cjs.map +1 -1
  55. package/_cjs/IO/api/forkAll.cjs +1 -1
  56. package/_cjs/IO/api/forkAll.cjs.map +1 -1
  57. package/_cjs/IO/api/forkIn.cjs +1 -1
  58. package/_cjs/IO/api/forkIn.cjs.map +1 -1
  59. package/_cjs/IO/api/forkScoped.cjs +1 -1
  60. package/_cjs/IO/api/forkScoped.cjs.map +1 -1
  61. package/_cjs/IO/api/fulfill.cjs +1 -1
  62. package/_cjs/IO/api/fulfill.cjs.map +1 -1
  63. package/_cjs/IO/api/interrupt.cjs +4 -4
  64. package/_cjs/IO/api/interrupt.cjs.map +1 -1
  65. package/_cjs/IO/api/memoize.cjs +4 -4
  66. package/_cjs/IO/api/memoize.cjs.map +1 -1
  67. package/_cjs/IO/api/onTermination.cjs +28 -0
  68. package/_cjs/IO/api/onTermination.cjs.map +1 -0
  69. package/_cjs/IO/api/raceFirst.cjs +1 -1
  70. package/_cjs/IO/api/raceFirst.cjs.map +1 -1
  71. package/_cjs/IO/api/repeat.cjs +2 -2
  72. package/_cjs/IO/api/repeat.cjs.map +1 -1
  73. package/_cjs/IO/api/retry.cjs +2 -2
  74. package/_cjs/IO/api/retry.cjs.map +1 -1
  75. package/_cjs/IO/api/schedule.cjs +2 -2
  76. package/_cjs/IO/api/schedule.cjs.map +1 -1
  77. package/_cjs/IO/api/timeout.cjs +3 -3
  78. package/_cjs/IO/api/timeout.cjs.map +1 -1
  79. package/_cjs/IO/api/zipC.cjs +5 -5
  80. package/_cjs/IO/api/zipC.cjs.map +1 -1
  81. package/_cjs/IO/api.cjs +4 -4
  82. package/_cjs/IO/api.cjs.map +1 -1
  83. package/_cjs/IO.cjs +13 -0
  84. package/_cjs/IO.cjs.map +1 -1
  85. package/_cjs/Layer/MemoMap.cjs +24 -24
  86. package/_cjs/Layer/MemoMap.cjs.map +1 -1
  87. package/_cjs/Layer/api.cjs +4 -4
  88. package/_cjs/Layer/api.cjs.map +1 -1
  89. package/_cjs/Ref/DerivedAll.cjs +1 -1
  90. package/_cjs/Ref/DerivedAll.cjs.map +1 -1
  91. package/_cjs/Ref/Synchronized/api.cjs +3 -3
  92. package/_cjs/Ref/Synchronized/api.cjs.map +1 -1
  93. package/_cjs/Ref/Synchronized/constructors.cjs +3 -3
  94. package/_cjs/Ref/Synchronized/constructors.cjs.map +1 -1
  95. package/_cjs/Ref/Synchronized/definition.cjs +3 -3
  96. package/_cjs/Ref/Synchronized/definition.cjs.map +1 -1
  97. package/_cjs/Ref/api/modify.cjs +10 -10
  98. package/_cjs/Ref/api/modify.cjs.map +1 -1
  99. package/_cjs/STM/api.cjs +15 -6
  100. package/_cjs/STM/api.cjs.map +1 -1
  101. package/_cjs/Scope/ReleaseMap/api/releaseAll.cjs +1 -1
  102. package/_cjs/Scope/ReleaseMap/api/releaseAll.cjs.map +1 -1
  103. package/_cjs/Scope/ReleaseMap/api.cjs +13 -13
  104. package/_cjs/Scope/ReleaseMap/api.cjs.map +1 -1
  105. package/_cjs/ScopedRef/api.cjs +1 -1
  106. package/_cjs/ScopedRef/api.cjs.map +1 -1
  107. package/_cjs/Sink/api.cjs +1475 -42
  108. package/_cjs/Sink/api.cjs.map +1 -1
  109. package/_cjs/Stream/api.cjs +42 -42
  110. package/_cjs/Stream/api.cjs.map +1 -1
  111. package/_cjs/TReentrantLock/api.cjs +297 -0
  112. package/_cjs/TReentrantLock/api.cjs.map +1 -0
  113. package/_cjs/TReentrantLock/definition.cjs +125 -0
  114. package/_cjs/TReentrantLock/definition.cjs.map +1 -0
  115. package/_cjs/TReentrantLock.cjs +32 -0
  116. package/_cjs/TReentrantLock.cjs.map +1 -0
  117. package/_cjs/TRef/api.cjs +7 -7
  118. package/_cjs/TRef/api.cjs.map +1 -1
  119. package/_cjs/collection/immutable/Conc/dropUntilIO.cjs +38 -0
  120. package/_cjs/collection/immutable/Conc/dropUntilIO.cjs.map +1 -0
  121. package/_cjs/collection/immutable/Conc/dropWhileIO.cjs +38 -0
  122. package/_cjs/collection/immutable/Conc/dropWhileIO.cjs.map +1 -0
  123. package/_cjs/collection/immutable/Conc/filterIO.cjs +35 -0
  124. package/_cjs/collection/immutable/Conc/filterIO.cjs.map +1 -0
  125. package/_cjs/collection/immutable/Conc.cjs +13 -0
  126. package/_cjs/collection/immutable/Conc.cjs.map +1 -1
  127. package/_cjs/data/Exit/foreachIO.cjs +1 -1
  128. package/_cjs/data/Exit/foreachIO.cjs.map +1 -1
  129. package/_mjs/Cached/api.mjs +5 -5
  130. package/_mjs/Cached/api.mjs.map +1 -1
  131. package/_mjs/Channel/api/mapOutIOC.mjs +9 -9
  132. package/_mjs/Channel/api/mapOutIOC.mjs.map +1 -1
  133. package/_mjs/Channel/api/mergeAllWith.mjs +18 -18
  134. package/_mjs/Channel/api/mergeAllWith.mjs.map +1 -1
  135. package/_mjs/Channel/api/mergeWith.mjs +5 -5
  136. package/_mjs/Channel/api/mergeWith.mjs.map +1 -1
  137. package/_mjs/Channel/api/run.mjs +3 -3
  138. package/_mjs/Channel/api/runCollect.mjs +3 -3
  139. package/_mjs/Channel/api/runDrain.mjs +3 -3
  140. package/_mjs/Channel/api.mjs +78 -33
  141. package/_mjs/Channel/api.mjs.map +1 -1
  142. package/_mjs/Channel/internal/ChannelExecutor.mjs +16 -16
  143. package/_mjs/Channel/internal/ChannelExecutor.mjs.map +1 -1
  144. package/_mjs/Channel/internal/MergeDecision.mjs +7 -0
  145. package/_mjs/Channel/internal/MergeDecision.mjs.map +1 -1
  146. package/_mjs/Channel/internal/SingleProducerAsyncInput.mjs +20 -20
  147. package/_mjs/Channel/internal/SingleProducerAsyncInput.mjs.map +1 -1
  148. package/_mjs/Fiber/api/awaitAll.mjs +1 -1
  149. package/_mjs/Fiber/api/awaitAll.mjs.map +1 -1
  150. package/_mjs/Fiber/api/fromIO.mjs +1 -1
  151. package/_mjs/Fiber/api/fromIO.mjs.map +1 -1
  152. package/_mjs/Fiber/api/interruptFork.mjs +3 -3
  153. package/_mjs/Fiber/api/interruptFork.mjs.map +1 -1
  154. package/_mjs/Fiber/api/zipWith.mjs +1 -1
  155. package/_mjs/Fiber/api/zipWith.mjs.map +1 -1
  156. package/_mjs/FiberRef/api/locallyScoped.mjs +3 -3
  157. package/_mjs/FiberRef/api/locallyScoped.mjs.map +1 -1
  158. package/_mjs/FiberRef/constructors.mjs +1 -1
  159. package/_mjs/FiberRef/constructors.mjs.map +1 -1
  160. package/_mjs/Future/api.mjs +1 -1
  161. package/_mjs/Future/api.mjs.map +1 -1
  162. package/_mjs/Hub/internal.mjs +1 -1
  163. package/_mjs/Hub/internal.mjs.map +1 -1
  164. package/_mjs/IO/api/asyncIO.mjs +4 -4
  165. package/_mjs/IO/api/asyncIO.mjs.map +1 -1
  166. package/_mjs/IO/api/bracketExit.mjs +1 -1
  167. package/_mjs/IO/api/bracketExit.mjs.map +1 -1
  168. package/_mjs/IO/api/environment.mjs +5 -5
  169. package/_mjs/IO/api/environment.mjs.map +1 -1
  170. package/_mjs/IO/api/foreachC.mjs +3 -3
  171. package/_mjs/IO/api/foreachC.mjs.map +1 -1
  172. package/_mjs/IO/api/foreachExec.mjs +3 -3
  173. package/_mjs/IO/api/foreachExec.mjs.map +1 -1
  174. package/_mjs/IO/api/forkAll.mjs +1 -1
  175. package/_mjs/IO/api/forkAll.mjs.map +1 -1
  176. package/_mjs/IO/api/forkIn.mjs +1 -1
  177. package/_mjs/IO/api/forkIn.mjs.map +1 -1
  178. package/_mjs/IO/api/forkScoped.mjs +1 -1
  179. package/_mjs/IO/api/forkScoped.mjs.map +1 -1
  180. package/_mjs/IO/api/fulfill.mjs +1 -1
  181. package/_mjs/IO/api/fulfill.mjs.map +1 -1
  182. package/_mjs/IO/api/interrupt.mjs +4 -4
  183. package/_mjs/IO/api/interrupt.mjs.map +1 -1
  184. package/_mjs/IO/api/memoize.mjs +4 -4
  185. package/_mjs/IO/api/memoize.mjs.map +1 -1
  186. package/_mjs/IO/api/onTermination.mjs +13 -0
  187. package/_mjs/IO/api/onTermination.mjs.map +1 -0
  188. package/_mjs/IO/api/raceFirst.mjs +1 -1
  189. package/_mjs/IO/api/raceFirst.mjs.map +1 -1
  190. package/_mjs/IO/api/repeat.mjs +2 -2
  191. package/_mjs/IO/api/repeat.mjs.map +1 -1
  192. package/_mjs/IO/api/retry.mjs +2 -2
  193. package/_mjs/IO/api/retry.mjs.map +1 -1
  194. package/_mjs/IO/api/schedule.mjs +2 -2
  195. package/_mjs/IO/api/schedule.mjs.map +1 -1
  196. package/_mjs/IO/api/timeout.mjs +3 -3
  197. package/_mjs/IO/api/timeout.mjs.map +1 -1
  198. package/_mjs/IO/api/zipC.mjs +5 -5
  199. package/_mjs/IO/api/zipC.mjs.map +1 -1
  200. package/_mjs/IO/api.mjs +4 -4
  201. package/_mjs/IO/api.mjs.map +1 -1
  202. package/_mjs/IO.mjs +1 -0
  203. package/_mjs/IO.mjs.map +1 -1
  204. package/_mjs/Layer/MemoMap.mjs +24 -24
  205. package/_mjs/Layer/MemoMap.mjs.map +1 -1
  206. package/_mjs/Layer/api.mjs +4 -4
  207. package/_mjs/Layer/api.mjs.map +1 -1
  208. package/_mjs/Ref/DerivedAll.mjs +1 -1
  209. package/_mjs/Ref/DerivedAll.mjs.map +1 -1
  210. package/_mjs/Ref/Synchronized/api.mjs +3 -3
  211. package/_mjs/Ref/Synchronized/api.mjs.map +1 -1
  212. package/_mjs/Ref/Synchronized/constructors.mjs +3 -3
  213. package/_mjs/Ref/Synchronized/constructors.mjs.map +1 -1
  214. package/_mjs/Ref/Synchronized/definition.mjs +3 -3
  215. package/_mjs/Ref/Synchronized/definition.mjs.map +1 -1
  216. package/_mjs/Ref/api/modify.mjs +10 -10
  217. package/_mjs/Ref/api/modify.mjs.map +1 -1
  218. package/_mjs/STM/api.mjs +13 -6
  219. package/_mjs/STM/api.mjs.map +1 -1
  220. package/_mjs/Scope/ReleaseMap/api/releaseAll.mjs +1 -1
  221. package/_mjs/Scope/ReleaseMap/api/releaseAll.mjs.map +1 -1
  222. package/_mjs/Scope/ReleaseMap/api.mjs +13 -13
  223. package/_mjs/Scope/ReleaseMap/api.mjs.map +1 -1
  224. package/_mjs/ScopedRef/api.mjs +1 -1
  225. package/_mjs/ScopedRef/api.mjs.map +1 -1
  226. package/_mjs/Sink/api.mjs +1287 -37
  227. package/_mjs/Sink/api.mjs.map +1 -1
  228. package/_mjs/Stream/api.mjs +42 -42
  229. package/_mjs/Stream/api.mjs.map +1 -1
  230. package/_mjs/TReentrantLock/api.mjs +243 -0
  231. package/_mjs/TReentrantLock/api.mjs.map +1 -0
  232. package/_mjs/TReentrantLock/definition.mjs +102 -0
  233. package/_mjs/TReentrantLock/definition.mjs.map +1 -0
  234. package/_mjs/TReentrantLock.mjs +4 -0
  235. package/_mjs/TReentrantLock.mjs.map +1 -0
  236. package/_mjs/TRef/api.mjs +7 -7
  237. package/_mjs/TRef/api.mjs.map +1 -1
  238. package/_mjs/collection/immutable/Conc/dropUntilIO.mjs +26 -0
  239. package/_mjs/collection/immutable/Conc/dropUntilIO.mjs.map +1 -0
  240. package/_mjs/collection/immutable/Conc/dropWhileIO.mjs +26 -0
  241. package/_mjs/collection/immutable/Conc/dropWhileIO.mjs.map +1 -0
  242. package/_mjs/collection/immutable/Conc/filterIO.mjs +22 -0
  243. package/_mjs/collection/immutable/Conc/filterIO.mjs.map +1 -0
  244. package/_mjs/collection/immutable/Conc.mjs +1 -0
  245. package/_mjs/collection/immutable/Conc.mjs.map +1 -1
  246. package/_mjs/data/Exit/foreachIO.mjs +1 -1
  247. package/_mjs/data/Exit/foreachIO.mjs.map +1 -1
  248. package/_src/Channel/api.ts +98 -11
  249. package/_src/Channel/internal/MergeDecision.ts +15 -0
  250. package/_src/IO/api/onTermination.ts +17 -0
  251. package/_src/IO/api.ts +1 -1
  252. package/_src/IO.ts +1 -0
  253. package/_src/STM/api.ts +9 -0
  254. package/_src/Sink/api.ts +1725 -36
  255. package/_src/TFuture/definition.ts +1 -1
  256. package/_src/TReentrantLock/api.ts +193 -0
  257. package/_src/TReentrantLock/definition.ts +86 -0
  258. package/_src/TReentrantLock.ts +4 -0
  259. package/_src/collection/immutable/Conc/dropUntilIO.ts +24 -0
  260. package/_src/collection/immutable/Conc/dropWhileIO.ts +26 -0
  261. package/_src/collection/immutable/Conc/filterIO.ts +16 -0
  262. package/_src/collection/immutable/Conc.ts +1 -0
  263. package/collection/immutable/Conc/dropUntilIO.d.ts +7 -0
  264. package/collection/immutable/Conc/dropWhileIO.d.ts +7 -0
  265. package/collection/immutable/Conc/filterIO.d.ts +7 -0
  266. package/collection/immutable/Conc.d.ts +1 -0
  267. package/package.json +3 -3
package/_cjs/Sink/api.cjs CHANGED
@@ -3,100 +3,1533 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.apFirst = apFirst;
7
+ exports.apFirstC = apFirstC;
8
+ exports.apSecond = apSecond;
9
+ exports.apSecondC = apSecondC;
10
+ exports.as = as;
6
11
  exports.collectAll = collectAll;
12
+ exports.collectAllWhileWith = void 0;
13
+ exports.collectLeftover = collectLeftover;
14
+ exports.defer = exports.contramapIO = exports.contramapChunksIO = exports.contramapChunks = exports.contramap = void 0;
15
+ exports.dimap = dimap;
16
+ exports.dimapChunks = dimapChunks;
17
+ exports.dimapChunksIO = dimapChunksIO;
18
+ exports.dimapIO = dimapIO;
7
19
  exports.drain = void 0;
8
- exports.dropWhile = dropWhile;
9
- exports.foreach = foreach;
10
- exports.foreachWhile = void 0;
20
+ exports.dropWhileIO = dropWhileIO;
21
+ exports.environment = environment;
22
+ exports.environmentWith = environmentWith;
23
+ exports.environmentWithIO = environmentWithIO;
24
+ exports.environmentWithSink = environmentWithSink;
25
+ exports.fail = fail;
26
+ exports.failNow = exports.failCauseNow = exports.failCause = void 0;
27
+ exports.filterInput = filterInput;
28
+ exports.filterInputIO = filterInputIO;
29
+ exports.findIO = findIO;
30
+ exports.flatMap = void 0;
31
+ exports.fromChannel = fromChannel;
32
+ exports.fromHub = fromHub;
33
+ exports.fromHubWithShutdown = fromHubWithShutdown;
34
+ exports.fromIO = void 0;
35
+ exports.fromPush = fromPush;
36
+ exports.fromQueueWithShutdown = exports.fromQueue = void 0;
37
+ exports.halt = halt;
38
+ exports.haltNow = haltNow;
39
+ exports.head = head;
40
+ exports.ignoreLeftover = void 0;
41
+ exports.last = last;
42
+ exports.leftover = leftover;
43
+ exports.log = log;
44
+ exports.makeCollectAll = makeCollectAll;
45
+ exports.makeCollectAllN = makeCollectAllN;
46
+ exports.makeDropUntil = makeDropUntil;
47
+ exports.makeDropUntilIO = makeDropUntilIO;
48
+ exports.makeDropWhile = makeDropWhile;
49
+ exports.makeFoldLeft = exports.makeFoldIO = exports.makeFoldChunksIO = exports.makeFoldChunks = exports.makeFold = void 0;
50
+ exports.makeFoldLeftChunks = makeFoldLeftChunks;
51
+ exports.makeFoldLeftChunksIO = makeFoldLeftChunksIO;
52
+ exports.makeFoldLeftIO = makeFoldLeftIO;
53
+ exports.makeFoldUntil = void 0;
54
+ exports.makeFoldUntilIO = makeFoldUntilIO;
55
+ exports.makeFoldWeighted = makeFoldWeighted;
56
+ exports.makeFoldWeightedDecomposeIO = exports.makeFoldWeightedDecompose = void 0;
57
+ exports.makeFoldWeightedIO = makeFoldWeightedIO;
58
+ exports.makeForeach = makeForeach;
59
+ exports.makeForeachChunk = void 0;
60
+ exports.makeForeachChunkWhile = makeForeachChunkWhile;
61
+ exports.makeForeachWhile = void 0;
62
+ exports.mapError_ = mapError_;
63
+ exports.matchSink_ = exports.map_ = exports.mapIO_ = void 0;
64
+ exports.orElse = orElse;
65
+ exports.provideEnvironment = provideEnvironment;
66
+ exports.race = race;
67
+ exports.raceWith = exports.raceBoth = void 0;
68
+ exports.service = service;
69
+ exports.serviceWith = void 0;
70
+ exports.serviceWithIO = serviceWithIO;
71
+ exports.serviceWithSink = serviceWithSink;
72
+ exports.splitWhere = splitWhere;
73
+ exports.succeed = succeed;
74
+ exports.succeedNow = succeedNow;
75
+ exports.summarized = void 0;
76
+ exports.timed = timed;
77
+ exports.unwrapScoped = exports.unwrap = void 0;
78
+ exports.zip = zip;
79
+ exports.zipC = zipC;
80
+ exports.zipWithC = exports.zipWith = void 0;
11
81
 
12
- var tsplus_module_1 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/base/collection/immutable/Conc/api"));
82
+ var tsplus_module_1 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/base/collection/immutable/Conc/api/empty"));
13
83
 
14
- var tsplus_module_2 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/io/Channel/core-api"));
84
+ var tsplus_module_2 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/base/collection/immutable/Conc/api"));
15
85
 
16
- var tsplus_module_3 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/io/Channel/api"));
86
+ var tsplus_module_3 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/io/Sink/definition"));
17
87
 
18
- var tsplus_module_4 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/io/Sink/definition"));
88
+ var tsplus_module_4 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/io/Channel/api"));
19
89
 
20
- var tsplus_module_5 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/base/collection/immutable/Conc/api/empty"));
90
+ var tsplus_module_5 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/io/Channel/core-api"));
21
91
 
22
- var tsplus_module_6 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/io/IO/api"));
92
+ var tsplus_module_6 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/io/Ref/api/set"));
93
+
94
+ var tsplus_module_7 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/io/Ref/api/get"));
95
+
96
+ var tsplus_module_8 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/io/Ref/constructors"));
97
+
98
+ var tsplus_module_9 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/io/IO/api"));
99
+
100
+ var tsplus_module_10 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/io/collection/immutable/Conc/mapIO"));
101
+
102
+ var tsplus_module_11 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/io/collection/immutable/Conc/dropUntilIO"));
103
+
104
+ var tsplus_module_12 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/io/collection/immutable/Conc/dropWhileIO"));
105
+
106
+ var tsplus_module_13 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/io/IO/api/environment"));
107
+
108
+ var tsplus_module_14 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/base/data/function/api"));
109
+
110
+ var tsplus_module_15 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/io/collection/immutable/Conc/filterIO"));
111
+
112
+ var tsplus_module_16 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/base/data/Maybe/constructors"));
113
+
114
+ var tsplus_module_17 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/base/data/Either/destructors"));
115
+
116
+ var tsplus_module_18 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/io/Queue/api/operations"));
117
+
118
+ var tsplus_module_19 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/io/IO/api/acquireRelease"));
119
+
120
+ var tsplus_module_20 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/base/data/Cause/api"));
121
+
122
+ var tsplus_module_21 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/base/data/Maybe/definition"));
123
+
124
+ var tsplus_module_22 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/base/data/Maybe/destructors"));
125
+
126
+ var tsplus_module_23 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/base/collection/immutable/Conc"));
127
+
128
+ var tsplus_module_24 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/base/collection/immutable/Conc/constructors"));
129
+
130
+ var tsplus_module_25 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/base/data/Either/api"));
131
+
132
+ var tsplus_module_26 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/base/data/Either/constructors"));
133
+
134
+ var tsplus_module_27 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/io/Channel/internal/MergeDecision"));
135
+
136
+ var tsplus_module_28 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/io/Channel/api/mergeWith"));
137
+
138
+ var tsplus_module_29 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/io/Hub/api"));
139
+
140
+ var tsplus_module_30 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/base/collection/Iterable/api"));
141
+
142
+ var tsplus_module_31 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/io/Clock/api"));
143
+
144
+ var tsplus_module_32 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/base/data/Duration/api"));
145
+
146
+ var tsplus_module_33 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/base/data/Exit/api"));
147
+
148
+ var _AtomicReference = /*#__PURE__*/require("@fncts/base/internal/AtomicReference");
23
149
 
24
150
  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); }
25
151
 
26
152
  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; }
27
153
 
28
- const foreachWhile = foreachWhile_1;
29
- exports.foreachWhile = foreachWhile;
154
+ const fileName_1 = "(@fncts/io) src/Sink/api.ts";
155
+ const collectAllWhileWith = collectAllWhileWith_1;
156
+ exports.collectAllWhileWith = collectAllWhileWith;
157
+ const contramap = contramap_1;
158
+ exports.contramap = contramap;
159
+ const contramapChunks = contramapChunks_1;
160
+ exports.contramapChunks = contramapChunks;
161
+ const contramapChunksIO = contramapChunksIO_1;
162
+ exports.contramapChunksIO = contramapChunksIO;
163
+ const contramapIO = contramapIO_1;
164
+ exports.contramapIO = contramapIO;
165
+ const defer = defer_1;
166
+ exports.defer = defer;
167
+ const failCause = failCause_1;
168
+ exports.failCause = failCause;
169
+ const failCauseNow = failCauseNow_1;
170
+ exports.failCauseNow = failCauseNow;
171
+ const failNow = failNow_1;
172
+ exports.failNow = failNow;
173
+ const flatMap = flatMap_1;
174
+ exports.flatMap = flatMap;
175
+ const fromQueue = fromQueue_1;
176
+ exports.fromQueue = fromQueue;
177
+ const fromQueueWithShutdown = fromQueueWithShutdown_1;
178
+ exports.fromQueueWithShutdown = fromQueueWithShutdown;
179
+ const fromIO = fromIO_1;
180
+ exports.fromIO = fromIO;
181
+ const ignoreLeftover = ignoreLeftover_1;
182
+ exports.ignoreLeftover = ignoreLeftover;
183
+ const makeForeachChunk = makeForeachChunk_1;
184
+ exports.makeForeachChunk = makeForeachChunk;
185
+ const makeForeachWhile = makeForeachWhile_1;
186
+ exports.makeForeachWhile = makeForeachWhile;
187
+ const makeFold = makeFold_1;
188
+ exports.makeFold = makeFold;
189
+ const makeFoldUntil = makeFoldUntil_1;
190
+ exports.makeFoldUntil = makeFoldUntil;
191
+ const makeFoldChunks = makeFoldChunks_1;
192
+ exports.makeFoldChunks = makeFoldChunks;
193
+ const makeFoldChunksIO = makeFoldChunksIO_1;
194
+ exports.makeFoldChunksIO = makeFoldChunksIO;
195
+ const makeFoldLeft = makeFoldLeft_1;
196
+ exports.makeFoldLeft = makeFoldLeft;
197
+ const makeFoldIO = makeFoldIO_1;
198
+ exports.makeFoldIO = makeFoldIO;
199
+ const makeFoldWeightedDecompose = makeFoldWeightedDecompose_1;
200
+ exports.makeFoldWeightedDecompose = makeFoldWeightedDecompose;
201
+ const makeFoldWeightedDecomposeIO = makeFoldWeightedDecomposeIO_1;
202
+ exports.makeFoldWeightedDecomposeIO = makeFoldWeightedDecomposeIO;
203
+ const map_ = map_1;
204
+ exports.map_ = map_;
205
+ const mapIO_ = mapIO_1;
206
+ exports.mapIO_ = mapIO_;
207
+ const matchSink_ = matchSink_1;
208
+ exports.matchSink_ = matchSink_;
209
+ const raceBoth = raceBoth_1;
210
+ exports.raceBoth = raceBoth;
211
+ const raceWith = raceWith_1;
212
+ exports.raceWith = raceWith;
213
+ const serviceWith = serviceWith_1;
214
+ exports.serviceWith = serviceWith;
215
+ const summarized = summarized_1;
216
+ exports.summarized = summarized;
217
+ const unwrap = unwrap_1;
218
+ exports.unwrap = unwrap;
219
+ const unwrapScoped = unwrapScoped_1;
220
+ exports.unwrapScoped = unwrapScoped;
221
+ const zipWith = zipWith_1;
222
+ exports.zipWith = zipWith;
223
+ const zipWithC = zipWithC_1;
224
+ exports.zipWithC = zipWithC;
30
225
 
31
- function collectLoop(state) {
32
- return tsplus_module_3.readWithCause(inp => collectLoop(tsplus_module_1.concat_(state, inp)), tsplus_module_2.failCauseNow, () => tsplus_module_2.endNow(state));
226
+ /**
227
+ * Like {@link zip}, but keeps only the result from this sink
228
+ *
229
+ * @tsplus fluent fncts.io.Sink apFirst
230
+ */
231
+ function apFirst(self, that) {
232
+ return zipWith_1(() => self, that, (z, _) => z, fileName_1 + ":14:22");
33
233
  }
34
234
  /**
35
- * A sink that collects all of its inputs into a chunk.
235
+ * Like {@link zipC}, but keeps only the result from this sink
36
236
  *
37
- * @tsplus static fncts.io.SinkOps collectAll
237
+ * @tsplus fluent fncts.io.Sink apFirstC
238
+ */
239
+
240
+
241
+ function apFirstC(self, that) {
242
+ return zipWithC_1(() => self, that, (z, _) => z, fileName_1 + ":26:23");
243
+ }
244
+ /**
245
+ * Like {@link zip}, but keeps only the result from the `that` sink
246
+ *
247
+ * @tsplus fluent fncts.io.Sink apSecond
248
+ */
249
+
250
+
251
+ function apSecond(self, that, __tsplusTrace) {
252
+ return zipWith_1(() => self, that, (_, z1) => z1, __tsplusTrace);
253
+ }
254
+ /**
255
+ * Like {@link zipC}, but keeps only the result from the `that` sink
256
+ *
257
+ * @tsplus fluent fncts.io.Sink apSecondC
258
+ */
259
+
260
+
261
+ function apSecondC(self, that, __tsplusTrace) {
262
+ return zipWithC_1(() => self, that, (_, z1) => z1, __tsplusTrace);
263
+ }
264
+ /**
265
+ * Replaces this sink's result with the provided value.
266
+ *
267
+ * @tsplus fluent fncts.io.Sink as
268
+ */
269
+
270
+
271
+ function as(self, z, __tsplusTrace) {
272
+ return map_1(self, () => z(), __tsplusTrace);
273
+ }
274
+ /**
275
+ * Repeatedly runs the sink and accumulates its results into a chunk
276
+ *
277
+ * @tsplus fluent fncts.io.Sink collectAll
278
+ */
279
+
280
+
281
+ function collectAll(self, __tsplusTrace) {
282
+ return collectAllWhileWith_1(self, () => tsplus_module_1.empty(), () => true, (s, z) => tsplus_module_2.append_(s, z), __tsplusTrace);
283
+ }
284
+ /**
285
+ * Repeatedly runs the sink for as long as its results satisfy the predicate
286
+ * `p`. The sink's results will be accumulated using the stepping function
287
+ * `f`.
288
+ *
289
+ * @tsplus fluent fncts.io.Sink collectAllWhileWith
38
290
  */
39
291
 
40
292
 
41
- function collectAll() {
42
- return new tsplus_module_4.Sink(collectLoop(tsplus_module_5.empty()));
293
+ function collectAllWhileWith_1(self, z, p, f, __tsplusTrace) {
294
+ return new tsplus_module_3.Sink(tsplus_module_5.flatMap_(tsplus_module_4.fromIO(() => tsplus_module_9.zip_(tsplus_module_8.make(() => tsplus_module_1.empty()), tsplus_module_8.make(() => false))), ([leftoversRef, upstreamDoneRef]) => {
295
+ const upstreamMarker = tsplus_module_4.readWith(inp => tsplus_module_5.apSecond_(tsplus_module_4.writeNow(inp), upstreamMarker), tsplus_module_4.failNow, x => tsplus_module_4.as_(tsplus_module_4.fromIO(() => tsplus_module_6.set_(upstreamDoneRef, true)), () => x));
296
+
297
+ function loop(currentResult) {
298
+ return tsplus_module_4.matchChannel_(tsplus_module_4.collectElements(self.channel), tsplus_module_4.failNow, ([leftovers, doneValue]) => {
299
+ if (p(doneValue)) {
300
+ return tsplus_module_5.apSecond_(tsplus_module_4.fromIO(() => tsplus_module_6.set_(leftoversRef, tsplus_module_2.flatten(leftovers))), tsplus_module_5.flatMap_(tsplus_module_4.fromIO(() => tsplus_module_7.get(upstreamDoneRef)), upstreamDone => {
301
+ const accumulatedResult = f(currentResult, doneValue);
302
+ if (upstreamDone) return tsplus_module_4.as_(tsplus_module_4.writeNow(tsplus_module_2.flatten(leftovers)), () => accumulatedResult);else return loop(accumulatedResult);
303
+ }));
304
+ } else {
305
+ return tsplus_module_4.as_(tsplus_module_4.writeNow(tsplus_module_2.flatten(leftovers)), () => currentResult);
306
+ }
307
+ });
308
+ }
309
+
310
+ return tsplus_module_4.pipeTo_(tsplus_module_4.pipeTo_(upstreamMarker, tsplus_module_4.bufferChunk(leftoversRef)), loop(z()));
311
+ }));
312
+ }
313
+ /**
314
+ * Collects the leftovers from the stream when the sink succeeds and returns
315
+ * them as part of the sink's result
316
+ *
317
+ * @tsplus getter fncts.io.Sink collectLeftover
318
+ */
319
+
320
+
321
+ function collectLeftover(self, __tsplusTrace) {
322
+ return new tsplus_module_3.Sink(tsplus_module_5.map_(tsplus_module_4.collectElements(self.channel), ([chunks, z]) => [z, tsplus_module_2.flatten(chunks)]));
323
+ }
324
+ /**
325
+ * Transforms this sink's input elements.
326
+ *
327
+ * @tsplus fluent fncts.io.Sink contramap
328
+ */
329
+
330
+
331
+ function contramap_1(self, f, __tsplusTrace) {
332
+ return contramapChunks_1(self, chunk => tsplus_module_2.map_(chunk, f), __tsplusTrace);
333
+ }
334
+ /**
335
+ * Transforms this sink's input chunks. `f` must preserve chunking-invariance
336
+ *
337
+ * @tsplus fluent fncts.io.Sink contramapChunks
338
+ */
339
+
340
+
341
+ function contramapChunks_1(self, f, __tsplusTrace) {
342
+ const loop = tsplus_module_4.readWith(chunk => tsplus_module_5.apSecond_(tsplus_module_4.writeNow(f(chunk)), loop), tsplus_module_4.failNow, tsplus_module_5.succeedNow);
343
+ return new tsplus_module_3.Sink(tsplus_module_4.pipeTo_(loop, self.channel));
344
+ }
345
+ /**
346
+ * Effectfully transforms this sink's input chunks. `f` must preserve
347
+ * chunking-invariance
348
+ *
349
+ * @tsplus fluent fncts.io.Sink contramapChunksIO
350
+ */
351
+
352
+
353
+ function contramapChunksIO_1(self, f, __tsplusTrace) {
354
+ const loop = tsplus_module_4.readWith(chunk => tsplus_module_5.apSecond_(tsplus_module_5.flatMap_(tsplus_module_4.fromIO(() => f(chunk)), tsplus_module_4.writeNow), loop), tsplus_module_4.failNow, tsplus_module_5.succeedNow);
355
+ return new tsplus_module_3.Sink(tsplus_module_4.pipeToOrFail_(loop, self.channel));
356
+ }
357
+ /**
358
+ * Effectfully transforms this sink's input elements.
359
+ *
360
+ * @tsplus fluent fncts.io.Sink contramapIO
361
+ */
362
+
363
+
364
+ function contramapIO_1(self, f, __tsplusTrace) {
365
+ return contramapChunksIO_1(self, chunk => tsplus_module_10.mapIO_(chunk, f), __tsplusTrace);
366
+ }
367
+ /**
368
+ * Transforms both inputs and result of this sink using the provided
369
+ * functions.
370
+ *
371
+ * @tsplus fluent fncts.io.Sink dimap
372
+ */
373
+
374
+
375
+ function dimap(self, f, g, __tsplusTrace) {
376
+ return map_1(contramap_1(self, f, __tsplusTrace), g, __tsplusTrace);
377
+ }
378
+ /**
379
+ * Transforms both input chunks and result of this sink using the provided
380
+ * functions.
381
+ *
382
+ * @tsplus fluent fncts.io.Sink dimapChunks
383
+ */
384
+
385
+
386
+ function dimapChunks(self, f, g, __tsplusTrace) {
387
+ return map_1(contramapChunks_1(self, f, __tsplusTrace), g, __tsplusTrace);
388
+ }
389
+ /**
390
+ * Effectfully transforms both input chunks and result of this sink using the
391
+ * provided functions. `f` and `g` must preserve chunking-invariance
392
+ *
393
+ * @tsplus fluent fncts.io.Sink dimapChunksIO
394
+ */
395
+
396
+
397
+ function dimapChunksIO(self, f, g, __tsplusTrace) {
398
+ return mapIO_1(contramapChunksIO_1(self, f, __tsplusTrace), g, __tsplusTrace);
399
+ }
400
+ /**
401
+ * Effectfully transforms both inputs and result of this sink using the
402
+ * provided functions.
403
+ *
404
+ * @tsplus fluent fncts.io.Sink dimapIO
405
+ */
406
+
407
+
408
+ function dimapIO(self, f, g, __tsplusTrace) {
409
+ return mapIO_1(contramapIO_1(self, f, __tsplusTrace), g, __tsplusTrace);
410
+ }
411
+ /**
412
+ * Returns a lazily constructed sink that may require effects for its
413
+ * creation.
414
+ *
415
+ * @tsplus static fncts.io.SinkOps defer
416
+ */
417
+
418
+
419
+ function defer_1(sink, __tsplusTrace) {
420
+ return new tsplus_module_3.Sink(tsplus_module_4.defer(() => sink().channel));
43
421
  }
44
422
 
45
- const drainLoop = /*#__PURE__*/tsplus_module_3.readWithCause(() => drainLoop, tsplus_module_2.failCauseNow, () => tsplus_module_3.unit);
423
+ const drainLoop = /*#__PURE__*/tsplus_module_4.readWithCause(() => drainLoop, tsplus_module_5.failCauseNow, () => tsplus_module_4.unit);
46
424
  /**
47
425
  * A sink that ignores all of its inputs.
48
426
  *
49
427
  * @tsplus static fncts.io.SinkOps drain
50
428
  */
51
429
 
52
- const drain = /*#__PURE__*/new tsplus_module_4.Sink(drainLoop);
430
+ const drain = /*#__PURE__*/new tsplus_module_3.Sink(drainLoop);
53
431
  /**
54
- * @tsplus static fncts.io.SinkOps dropWhile
432
+ * Drops incoming elements until the predicate `p` is satisfied.
433
+ *
434
+ * @tsplus static fncts.io.SinkOps dropUntil
55
435
  */
56
436
 
57
437
  exports.drain = drain;
58
438
 
59
- function dropWhile(predicate) {
60
- const loop = tsplus_module_3.readWith(inp => {
61
- const leftover = tsplus_module_1.dropWhile_(inp, predicate);
62
- const more = tsplus_module_1.isEmpty(leftover);
439
+ function makeDropUntil(p, __tsplusTrace) {
440
+ const loop = tsplus_module_4.readWith(inp => {
441
+ const leftover = tsplus_module_2.dropUntil(inp, p);
442
+ const more = tsplus_module_2.isEmpty(leftover);
63
443
 
64
444
  if (more) {
65
445
  return loop;
66
446
  } else {
67
- return tsplus_module_2.apSecond_(tsplus_module_3.writeNow(leftover), tsplus_module_3.id());
447
+ return tsplus_module_5.apSecond_(tsplus_module_4.writeNow(leftover), tsplus_module_4.id());
68
448
  }
69
- }, tsplus_module_3.failNow, () => tsplus_module_3.unit);
70
- return new tsplus_module_4.Sink(loop);
449
+ }, tsplus_module_4.failNow, () => tsplus_module_4.unit);
450
+ return new tsplus_module_3.Sink(loop);
71
451
  }
72
452
  /**
73
- * A sink that executes the provided effectful function for every element fed to it.
453
+ * Drops incoming elements until the effectful predicate `p` is satisfied.
74
454
  *
75
- * @tsplus static fncts.io.SinkOps foreach
455
+ * @tsplus static fncts.io.SinkOps dropUntilIO
76
456
  */
77
457
 
78
458
 
79
- function foreach(f) {
80
- return foreachWhile_1(inp => tsplus_module_6.as_(f(inp), () => true));
459
+ function makeDropUntilIO(p, __tsplusTrace) {
460
+ const loop = tsplus_module_4.readWith(inp => tsplus_module_4.unwrap(() => tsplus_module_9.map_(tsplus_module_11.dropUntilIO(inp, p, __tsplusTrace), leftover => tsplus_module_2.isEmpty(leftover) ? loop : tsplus_module_5.apSecond_(tsplus_module_4.writeNow(leftover), tsplus_module_4.id()), __tsplusTrace)), tsplus_module_4.failNow, () => tsplus_module_4.unit);
461
+ return new tsplus_module_3.Sink(loop);
81
462
  }
463
+ /**
464
+ * Drops incoming elements as long as the predicate `p` is satisfied.
465
+ *
466
+ * @tsplus static fncts.io.SinkOps dropWhile
467
+ */
468
+
469
+
470
+ function makeDropWhile(predicate, __tsplusTrace) {
471
+ const loop = tsplus_module_4.readWith(inp => {
472
+ const leftover = tsplus_module_2.dropWhile_(inp, predicate);
473
+ const more = tsplus_module_2.isEmpty(leftover);
474
+
475
+ if (more) {
476
+ return loop;
477
+ } else {
478
+ return tsplus_module_5.apSecond_(tsplus_module_4.writeNow(leftover), tsplus_module_4.id());
479
+ }
480
+ }, tsplus_module_4.failNow, () => tsplus_module_4.unit);
481
+ return new tsplus_module_3.Sink(loop);
482
+ }
483
+ /**
484
+ * Drops incoming elements as long as the effectful predicate `p` is
485
+ * satisfied.
486
+ *
487
+ * @tsplus static fncts.io.SinkOps dropWhileIO
488
+ */
82
489
 
83
- function foreachWhileLoop(f, chunk, idx, len, cont) {
84
- if (idx === len) {
85
- return cont;
86
- }
87
490
 
88
- return tsplus_module_3.catchAll_(tsplus_module_2.flatMap_(tsplus_module_3.fromIO(() => f(tsplus_module_1.unsafeGet_(chunk, idx))), b => b ? foreachWhileLoop(f, chunk, idx + 1, len, cont) : tsplus_module_3.writeNow(tsplus_module_1.drop_(chunk, idx))), e => tsplus_module_2.apSecond_(tsplus_module_3.writeNow(tsplus_module_1.drop_(chunk, idx)), tsplus_module_3.failNow(e)));
491
+ function dropWhileIO(p, __tsplusTrace) {
492
+ const loop = tsplus_module_4.readWith(inp => tsplus_module_4.unwrap(() => tsplus_module_9.map_(tsplus_module_12.dropWhileIO(inp, p, __tsplusTrace), leftover => tsplus_module_2.isEmpty(leftover) ? loop : tsplus_module_5.apSecond_(tsplus_module_4.writeNow(leftover), tsplus_module_4.id()), __tsplusTrace)), tsplus_module_4.failNow, () => tsplus_module_4.unit);
493
+ return new tsplus_module_3.Sink(loop);
89
494
  }
90
495
  /**
91
- * A sink that executes the provided effectful function for every element fed to it
92
- * until `f` evaluates to `false`.
496
+ * Accesses the whole environment of the sink.
93
497
  *
94
- * @tsplus static fncts.io.SinkOps foreachWhile
498
+ * @tsplus static fncts.io.SinkOps environment
499
+ */
500
+
501
+
502
+ function environment(__tsplusTrace) {
503
+ return fromIO_1(() => tsplus_module_13.environment(__tsplusTrace), __tsplusTrace);
504
+ }
505
+ /**
506
+ * Accesses the environment of the sink.
507
+ *
508
+ * @tsplus static fncts.io.SinkOps environmentWith
509
+ */
510
+
511
+
512
+ function environmentWith(f, __tsplusTrace) {
513
+ return fromIO_1(() => tsplus_module_13.environmentWith(f, __tsplusTrace), __tsplusTrace);
514
+ }
515
+ /**
516
+ * Accesses the environment of the sink in the context of an effect.
517
+ *
518
+ * @tsplus static fncts.io.SinkOps environmentWithIO
519
+ */
520
+
521
+
522
+ function environmentWithIO(f, __tsplusTrace) {
523
+ return fromIO_1(() => tsplus_module_13.environmentWithIO(f, __tsplusTrace), __tsplusTrace);
524
+ }
525
+ /**
526
+ * Accesses the environment of the sink in the context of a sink.
527
+ *
528
+ * @tsplus static fncts.io.SinkOps environmentWithSink
529
+ */
530
+
531
+
532
+ function environmentWithSink(f, __tsplusTrace) {
533
+ return new tsplus_module_3.Sink(tsplus_module_4.unwrap(() => tsplus_module_13.environmentWith(tsplus_module_14.compose_(f, s => s.channel), __tsplusTrace)));
534
+ }
535
+ /**
536
+ * A sink that always fails with the specified error.
537
+ *
538
+ * @tsplus static fncts.io.SinkOps fail
539
+ */
540
+
541
+
542
+ function fail(e, __tsplusTrace) {
543
+ return new tsplus_module_3.Sink(tsplus_module_4.fail(e));
544
+ }
545
+ /**
546
+ * Creates a sink halting with a specified cause.
547
+ *
548
+ * @tsplus static fncts.io.SinkOps failCause
549
+ */
550
+
551
+
552
+ function failCause_1(cause, __tsplusTrace) {
553
+ return new tsplus_module_3.Sink(tsplus_module_5.failCause(cause));
554
+ }
555
+ /**
556
+ * Creates a sink halting with a specified cause.
557
+ *
558
+ * @tsplus static fncts.io.SinkOps failCauseNow
559
+ */
560
+
561
+
562
+ function failCauseNow_1(cause, __tsplusTrace) {
563
+ return new tsplus_module_3.Sink(tsplus_module_5.failCauseNow(cause));
564
+ }
565
+ /**
566
+ * A sink that always fails with the specified error.
567
+ *
568
+ * @tsplus static fncts.io.SinkOps failNow
569
+ */
570
+
571
+
572
+ function failNow_1(e, __tsplusTrace) {
573
+ return new tsplus_module_3.Sink(tsplus_module_4.failNow(e));
574
+ }
575
+ /**
576
+ * Filters the sink's input with the given predicate
577
+ *
578
+ * @tsplus static fncts.io.SinkOps filterInput
579
+ */
580
+
581
+
582
+ function filterInput(self, p, __tsplusTrace) {
583
+ return contramapChunks_1(self, chunk => tsplus_module_2.filter_(chunk, p), __tsplusTrace);
584
+ }
585
+ /**
586
+ * Filters the sink's input with the given IO predicate
587
+ *
588
+ * @tsplus static fncts.io.SinkOps filterInputIO
589
+ */
590
+
591
+
592
+ function filterInputIO(self, p, __tsplusTrace) {
593
+ return contramapChunksIO_1(self, chunk => tsplus_module_15.filterIO(chunk, p), __tsplusTrace);
594
+ }
595
+ /**
596
+ * Creates a sink that produces values until one verifies the predicate `f`.
597
+ *
598
+ * @tsplus fluent fncts.io.Sink findIO
599
+ */
600
+
601
+
602
+ function findIO(self, f, __tsplusTrace) {
603
+ return new tsplus_module_3.Sink(tsplus_module_5.flatMap_(tsplus_module_4.fromIO(() => tsplus_module_9.zip_(tsplus_module_8.make(() => tsplus_module_1.empty()), tsplus_module_8.make(() => false))), ([leftoversRef, upstreamDoneRef]) => {
604
+ const upstreamMarker = tsplus_module_4.readWith(inp => tsplus_module_5.apSecond_(tsplus_module_4.writeNow(inp), upstreamMarker), tsplus_module_4.failNow, x => tsplus_module_4.as_(tsplus_module_4.fromIO(() => tsplus_module_6.set_(upstreamDoneRef, true)), () => x));
605
+ const loop = tsplus_module_4.matchChannel_(tsplus_module_4.collectElements(self.channel), tsplus_module_4.failNow, ([leftovers, doneValue]) => tsplus_module_5.flatMap_(tsplus_module_4.fromIO(() => f(doneValue)), satisfied => tsplus_module_5.apSecond_(tsplus_module_4.fromIO(() => tsplus_module_6.set_(leftoversRef, tsplus_module_2.flatten(leftovers))), tsplus_module_5.flatMap_(tsplus_module_4.fromIO(() => tsplus_module_7.get(upstreamDoneRef)), upstreamDone => {
606
+ if (satisfied) return tsplus_module_4.as_(tsplus_module_4.writeNow(tsplus_module_2.flatten(leftovers)), () => tsplus_module_16.just(doneValue));else if (upstreamDone) return tsplus_module_4.as_(tsplus_module_4.writeNow(tsplus_module_2.flatten(leftovers)), () => tsplus_module_16.nothing());else return loop;
607
+ }))));
608
+ return tsplus_module_4.pipeTo_(tsplus_module_4.pipeTo_(upstreamMarker, tsplus_module_4.bufferChunk(leftoversRef)), loop);
609
+ }));
610
+ }
611
+ /**
612
+ * Runs this sink until it yields a result, then uses that result to create
613
+ * another sink from the provided function which will continue to run until it
614
+ * yields a result.
615
+ *
616
+ * This function essentially runs sinks in sequence.
617
+ *
618
+ * @tsplus fluent fncts.io.Sink flatMap
619
+ */
620
+
621
+
622
+ function flatMap_1(self, f, __tsplusTrace) {
623
+ return matchSink_1(self, failNow_1, f, __tsplusTrace);
624
+ }
625
+ /**
626
+ * Creates a sink from a {@link Channel}
627
+ *
628
+ * @tsplus static fncts.io.SinkOps fromChannel
629
+ * @tsplus static fncts.io.SinkOps __call
630
+ */
631
+
632
+
633
+ function fromChannel(channel) {
634
+ return new tsplus_module_3.Sink(channel);
635
+ }
636
+ /**
637
+ * Creates a sink from a chunk processing function.
638
+ *
639
+ * @tsplus static fncts.io.SinkOps fromPush
640
+ */
641
+
642
+
643
+ function fromPush(push, __tsplusTrace) {
644
+ return new tsplus_module_3.Sink(tsplus_module_4.unwrapScoped(() => tsplus_module_9.map_(push, fromPushPull, __tsplusTrace)));
645
+ }
646
+
647
+ function fromPushPull(push) {
648
+ return tsplus_module_4.readWith(inp => tsplus_module_4.matchChannel_(tsplus_module_4.fromIO(() => push(tsplus_module_16.just(inp))), ([r, leftovers]) => tsplus_module_17.match_(r, e => tsplus_module_5.apSecond_(tsplus_module_4.writeNow(leftovers), tsplus_module_4.failNow(e)), z => tsplus_module_5.apSecond_(tsplus_module_4.writeNow(leftovers), tsplus_module_5.succeedNow(z))), () => fromPushPull(push)), tsplus_module_4.failNow, () => tsplus_module_4.matchChannel_(tsplus_module_4.fromIO(() => push(tsplus_module_16.nothing())), ([r, leftovers]) => tsplus_module_17.match_(r, e => tsplus_module_5.apSecond_(tsplus_module_4.writeNow(leftovers), tsplus_module_4.failNow(e)), z => tsplus_module_5.apSecond_(tsplus_module_4.writeNow(leftovers), tsplus_module_5.succeedNow(z))), () => tsplus_module_4.fromIO(() => tsplus_module_9.halt(() => new Error("empty sink"), fileName_1 + ":591:37"))));
649
+ }
650
+ /**
651
+ * Create a sink which enqueues each element into the specified queue.
652
+ *
653
+ * @tsplus static fncts.io.SinkOps fromQueue
654
+ */
655
+
656
+
657
+ function fromQueue_1(queue, __tsplusTrace) {
658
+ return unwrap_1(() => tsplus_module_9.map_(tsplus_module_9.succeed(queue, __tsplusTrace), queue => makeForeachChunk_1(inp => tsplus_module_18.offerAll_(queue, inp), __tsplusTrace), __tsplusTrace));
659
+ }
660
+ /**
661
+ * Create a sink which enqueues each element into the specified queue. The
662
+ * queue will be shutdown once the stream is closed.
663
+ *
664
+ * @tsplus static fncts.io.SinkOps fromQueueWithShutdown
665
+ */
666
+
667
+
668
+ function fromQueueWithShutdown_1(queue, __tsplusTrace) {
669
+ return unwrapScoped_1(() => tsplus_module_9.map_(tsplus_module_19.acquireRelease(() => tsplus_module_9.succeed(queue, __tsplusTrace), queue => tsplus_module_18.shutdown(queue)), queue => fromQueue_1(() => queue, __tsplusTrace), __tsplusTrace), __tsplusTrace);
670
+ }
671
+ /**
672
+ * Create a sink which publishes each element to the specified hub.
673
+ *
674
+ * @tsplus static fncts.io.SinkOps fromHub
675
+ */
676
+
677
+
678
+ function fromHub(hub, __tsplusTrace) {
679
+ return fromQueue_1(hub, __tsplusTrace);
680
+ }
681
+ /**
682
+ * Create a sink which publishes each element to the specified hub. The hub
683
+ * will be shutdown once the stream is closed.
684
+ *
685
+ * @tsplus static fncts.io.SinkOps fromHubWithShutdown
686
+ */
687
+
688
+
689
+ function fromHubWithShutdown(hub, __tsplusTrace) {
690
+ return fromQueueWithShutdown_1(hub, __tsplusTrace);
691
+ }
692
+ /**
693
+ * Creates a single-value sink produced from an effect
694
+ *
695
+ * @tsplus static fncts.io.SinkOps fromIO
696
+ */
697
+
698
+
699
+ function fromIO_1(b, __tsplusTrace) {
700
+ return new tsplus_module_3.Sink(tsplus_module_4.fromIO(b));
701
+ }
702
+ /**
703
+ * Creates a sink halting with the specified unchecked value.
704
+ *
705
+ * @tsplus static fncts.io.SinkOps halt
706
+ */
707
+
708
+
709
+ function halt(defect, __tsplusTrace) {
710
+ return failCause_1(() => tsplus_module_20.halt(defect()), __tsplusTrace);
711
+ }
712
+ /**
713
+ * Creates a sink halting with the specified unchecked value.
714
+ *
715
+ * @tsplus static fncts.io.SinkOps haltNow
716
+ */
717
+
718
+
719
+ function haltNow(defect, __tsplusTrace) {
720
+ return failCauseNow_1(tsplus_module_20.halt(defect), __tsplusTrace);
721
+ }
722
+ /**
723
+ * Creates a sink containing the first value.
724
+ *
725
+ * @tsplus static fncts.io.SinkOps head
726
+ */
727
+
728
+
729
+ function head(__tsplusTrace) {
730
+ return makeFold_1(() => tsplus_module_16.nothing(), elem => tsplus_module_21.isNothing(elem), (s, inp) => tsplus_module_22.match_(s, () => tsplus_module_16.just(inp), () => s), __tsplusTrace);
731
+ }
732
+ /**
733
+ * Drains the remaining elements from the stream after the sink finishes
734
+ *
735
+ * @tsplus getter fncts.io.Sink ignoreLeftover
736
+ */
737
+
738
+
739
+ function ignoreLeftover_1(self, __tsplusTrace) {
740
+ return new tsplus_module_3.Sink(tsplus_module_4.drain(self.channel));
741
+ }
742
+ /**
743
+ * Creates a sink containing the last value.
744
+ *
745
+ * @tsplus static fncts.io.SinkOps last
746
+ */
747
+
748
+
749
+ function last(__tsplusTrace) {
750
+ return makeFoldLeft_1(() => tsplus_module_16.nothing(), (_, inp) => tsplus_module_16.just(inp));
751
+ }
752
+ /**
753
+ * Creates a sink that does not consume any input but provides the given chunk
754
+ * as its leftovers
755
+ *
756
+ * @tsplus static fncts.io.SinkOps leftover
757
+ */
758
+
759
+
760
+ function leftover(c, __tsplusTrace) {
761
+ return new tsplus_module_3.Sink(tsplus_module_4.write(c));
762
+ }
763
+ /**
764
+ * Logs the specified message at the current log level.
765
+ *
766
+ * @tsplus static fncts.io.SinkOps log
767
+ */
768
+
769
+
770
+ function log(message, __tsplusTrace) {
771
+ return fromIO_1(() => tsplus_module_9.log(message, __tsplusTrace), __tsplusTrace);
772
+ }
773
+ /**
774
+ * A sink that collects all of its inputs into a chunk.
775
+ *
776
+ * @tsplus static fncts.io.SinkOps collectAll
777
+ */
778
+
779
+
780
+ function makeCollectAll() {
781
+ return new tsplus_module_3.Sink(collectLoop(tsplus_module_1.empty()));
782
+ }
783
+
784
+ function collectLoop(state) {
785
+ return tsplus_module_4.readWithCause(inp => collectLoop(tsplus_module_2.concat_(state, inp)), tsplus_module_5.failCauseNow, () => tsplus_module_5.endNow(state));
786
+ }
787
+ /**
788
+ * A sink that collects first `n` elements into a chunk. Note that the chunk
789
+ * is preallocated and must fit in memory.
790
+ *
791
+ * @tsplus static fncts.io.SinkOps collectAllN
792
+ */
793
+
794
+
795
+ function makeCollectAllN(n) {
796
+ return flatMap_1(fromIO_1(() => tsplus_module_9.succeed(() => new tsplus_module_23.ConcBuilder(), fileName_1 + ":755:32"), fileName_1 + ":755:21"), builder => map_1(makeFoldUntil_1(() => builder, n, (builder, inp) => builder.append(inp), fileName_1 + ":756:19"), builder => builder.result(), fileName_1 + ":756:95"), fileName_1 + ":755:64");
797
+ }
798
+ /**
799
+ * A sink that executes the provided effectful function for every element fed to it.
800
+ *
801
+ * @tsplus static fncts.io.SinkOps foreach
802
+ */
803
+
804
+
805
+ function makeForeach(f, __tsplusTrace) {
806
+ return makeForeachWhile_1(inp => tsplus_module_9.as_(f(inp), () => true), __tsplusTrace);
807
+ }
808
+ /**
809
+ * A sink that executes the provided effectful function for every chunk fed to
810
+ * it.
811
+ *
812
+ * @tsplus static fncts.io.SinkOps foreachChunk
813
+ */
814
+
815
+
816
+ function makeForeachChunk_1(f, __tsplusTrace) {
817
+ const process = tsplus_module_4.readWithCause(inp => tsplus_module_5.apSecond_(tsplus_module_4.fromIO(() => f(inp)), process), tsplus_module_5.failCauseNow, () => tsplus_module_4.unit);
818
+ return new tsplus_module_3.Sink(process);
819
+ }
820
+ /**
821
+ * A sink that executes the provided effectful function for every element fed to it
822
+ * until `f` evaluates to `false`.
823
+ *
824
+ * @tsplus static fncts.io.SinkOps foreachWhile
825
+ */
826
+
827
+
828
+ function makeForeachWhile_1(f, __tsplusTrace) {
829
+ const process = tsplus_module_4.readWithCause(inp => foreachWhileLoop(f, inp, 0, inp.length, process), tsplus_module_5.failCauseNow, () => tsplus_module_4.unit);
830
+ return new tsplus_module_3.Sink(process);
831
+ }
832
+
833
+ function foreachWhileLoop(f, chunk, idx, len, cont) {
834
+ if (idx === len) {
835
+ return cont;
836
+ }
837
+
838
+ return tsplus_module_4.catchAll_(tsplus_module_5.flatMap_(tsplus_module_4.fromIO(() => f(tsplus_module_2.unsafeGet_(chunk, idx))), b => b ? foreachWhileLoop(f, chunk, idx + 1, len, cont) : tsplus_module_4.writeNow(tsplus_module_2.drop_(chunk, idx))), e => tsplus_module_5.apSecond_(tsplus_module_4.writeNow(tsplus_module_2.drop_(chunk, idx)), tsplus_module_4.failNow(e)));
839
+ }
840
+ /**
841
+ * A sink that executes the provided effectful function for every chunk fed to
842
+ * it until `f` evaluates to `false`.
843
+ *
844
+ * @tsplus static fncts.io.SinkOps foreachChunkWhile
845
+ */
846
+
847
+
848
+ function makeForeachChunkWhile(f, __tsplusTrace) {
849
+ const reader = tsplus_module_4.readWith(inp => tsplus_module_5.flatMap_(tsplus_module_4.fromIO(() => f(inp)), cont => cont ? reader : tsplus_module_4.unit), tsplus_module_4.failNow, () => tsplus_module_4.unit);
850
+ return new tsplus_module_3.Sink(reader);
851
+ }
852
+ /**
853
+ * A sink that folds its inputs with the provided function, termination
854
+ * predicate and initial state.
855
+ *
856
+ * @tsplus static fncts.io.SinkOps fold
857
+ */
858
+
859
+
860
+ function makeFold_1(z, contFn, f, __tsplusTrace) {
861
+ return defer_1(() => new tsplus_module_3.Sink(foldReader(z(), contFn, f)), __tsplusTrace);
862
+ }
863
+ /**
864
+ * @tsplus tailRec
865
+ */
866
+
867
+
868
+ function foldChunkSplit(contFn, f, s, chunk, idx, len) {
869
+ var contFn_1 = contFn,
870
+ f_1 = f,
871
+ s_1 = s,
872
+ chunk_1 = chunk,
873
+ idx_1 = idx,
874
+ len_1 = len;
875
+ var contFn_2 = contFn,
876
+ f_2 = f,
877
+ s_2 = s,
878
+ chunk_2 = chunk,
879
+ idx_2 = idx,
880
+ len_2 = len;
881
+
882
+ while (1) {
883
+ if (idx_1 === len_1) {
884
+ return [s_1, tsplus_module_1.empty()];
885
+ } else {
886
+ const s1 = f_1(s_1, tsplus_module_2.unsafeGet_(chunk_1, idx_1));
887
+
888
+ if (contFn_1(s1)) {
889
+ contFn_2 = contFn_1;
890
+ f_2 = f_1;
891
+ s_2 = s1;
892
+ chunk_2 = chunk_1;
893
+ idx_2 = idx_1 + 1;
894
+ len_2 = len_1;
895
+ contFn_1 = contFn_2;
896
+ f_1 = f_2;
897
+ s_1 = s_2;
898
+ chunk_1 = chunk_2;
899
+ idx_1 = idx_2;
900
+ len_1 = len_2;
901
+ continue;
902
+ } else {
903
+ return [s1, tsplus_module_2.drop_(chunk_1, idx_1 + 1)];
904
+ }
905
+ }
906
+ }
907
+ }
908
+
909
+ function foldReader(s, contFn, f) {
910
+ if (!contFn(s)) {
911
+ return tsplus_module_5.succeedNow(s);
912
+ } else {
913
+ return tsplus_module_4.readWith(inp => {
914
+ const [nextS, leftovers] = foldChunkSplit(contFn, f, s, inp, 0, inp.length);
915
+
916
+ if (tsplus_module_2.isNonEmpty(leftovers)) {
917
+ return tsplus_module_4.as_(tsplus_module_4.writeNow(leftovers), () => nextS);
918
+ } else {
919
+ return foldReader(nextS, contFn, f);
920
+ }
921
+ }, _ => tsplus_module_4.failNow(_), _ => tsplus_module_5.succeedNow(_));
922
+ }
923
+ }
924
+ /**
925
+ * Creates a sink that folds elements of type `In` into a structure of type
926
+ * `S` until `max` elements have been folded.
927
+ *
928
+ * Like {@link foldWeighted}, but with a constant cost function of 1.
929
+ *
930
+ * @tsplus static fncts.io.SinkOps foldUntil
931
+ */
932
+
933
+
934
+ function makeFoldUntil_1(z, max, f, __tsplusTrace) {
935
+ return unwrap_1(() => tsplus_module_9.map_(tsplus_module_9.succeed(max, __tsplusTrace), max => map_1(makeFold_1(() => [z(), 0], ([_, n]) => n < max, ([o, count], i) => [f(o, i), count + 1], __tsplusTrace), ([s]) => s, __tsplusTrace), __tsplusTrace));
936
+ }
937
+ /**
938
+ * A sink that folds its input chunks with the provided function, termination
939
+ * predicate and initial state. `contFn` condition is checked only for the
940
+ * initial value and at the end of processing of each chunk. `f` and `contFn`
941
+ * must preserve chunking-invariance.
942
+ *
943
+ * @tsplus static fncts.io.SinkOps foldChunks
944
+ */
945
+
946
+
947
+ function makeFoldChunks_1(z, contFn, f, __tsplusTrace) {
948
+ return defer_1(() => new tsplus_module_3.Sink(foldChunksReader(z(), contFn, f)), __tsplusTrace);
949
+ }
950
+
951
+ function foldChunksReader(s, contFn, f) {
952
+ if (!contFn(s)) {
953
+ return tsplus_module_5.succeedNow(s);
954
+ } else {
955
+ return tsplus_module_4.readWith(inp => {
956
+ const nextS = f(s, inp);
957
+ return foldChunksReader(nextS, contFn, f);
958
+ }, err => tsplus_module_4.failNow(err), _ => tsplus_module_5.succeedNow(_));
959
+ }
960
+ }
961
+ /**
962
+ * A sink that effectfully folds its input chunks with the provided function,
963
+ * termination predicate and initial state. `contFn` condition is checked only
964
+ * for the initial value and at the end of processing of each chunk. `f` and
965
+ * `contFn` must preserve chunking-invariance.
966
+ *
967
+ * @tsplus static fncts.io.SinkOps foldChunksIO
968
+ */
969
+
970
+
971
+ function makeFoldChunksIO_1(z, contFn, f, __tsplusTrace) {
972
+ return defer_1(() => new tsplus_module_3.Sink(foldChunksIOReader(z(), contFn, f)), __tsplusTrace);
973
+ }
974
+
975
+ function foldChunksIOReader(s, contFn, f) {
976
+ if (!contFn(s)) {
977
+ return tsplus_module_5.succeedNow(s);
978
+ } else {
979
+ return tsplus_module_4.readWith(inp => tsplus_module_5.flatMap_(tsplus_module_4.fromIO(() => f(s, inp)), s => foldChunksIOReader(s, contFn, f)), err => tsplus_module_4.failNow(err), _ => tsplus_module_5.succeedNow(_));
980
+ }
981
+ }
982
+ /**
983
+ * A sink that folds its inputs with the provided function and initial state.
984
+ *
985
+ * @tsplus static fncts.io.SinkOps foldLeft
986
+ */
987
+
988
+
989
+ function makeFoldLeft_1(z, f) {
990
+ return ignoreLeftover_1(makeFold_1(z, () => true, f, fileName_1 + ":1006:19"), fileName_1 + ":1006:37");
991
+ }
992
+ /**
993
+ * A sink that folds its input chunks with the provided function and initial
994
+ * state. `f` must preserve chunking-invariance.
995
+ *
996
+ * @tsplus static fncts.io.SinkOps foldLeftChunks
997
+ */
998
+
999
+
1000
+ function makeFoldLeftChunks(z, f) {
1001
+ return ignoreLeftover_1(makeFoldChunks_1(z, () => true, f, fileName_1 + ":1019:25"), fileName_1 + ":1019:43");
1002
+ }
1003
+ /**
1004
+ * A sink that effectfully folds its input chunks with the provided function
1005
+ * and initial state. `f` must preserve chunking-invariance.
1006
+ *
1007
+ * @tsplus static fncts.io.SinkOps foldLeftChunksIO
1008
+ */
1009
+
1010
+
1011
+ function makeFoldLeftChunksIO(z, f, __tsplusTrace) {
1012
+ return makeFoldChunksIO_1(z, () => true, f, __tsplusTrace);
1013
+ }
1014
+ /**
1015
+ * A sink that effectfully folds its inputs with the provided function and
1016
+ * initial state.
1017
+ *
1018
+ * @tsplus static fncts.io.SinkOps foldLeftIO
1019
+ */
1020
+
1021
+
1022
+ function makeFoldLeftIO(z, f, __tsplusTrace) {
1023
+ return makeFoldIO_1(z, () => true, f);
1024
+ }
1025
+ /**
1026
+ * A sink that effectfully folds its inputs with the provided function,
1027
+ * termination predicate and initial state.
1028
+ *
1029
+ * @tsplus static fncts.io.SinkOps foldIO
1030
+ */
1031
+
1032
+
1033
+ function makeFoldIO_1(z, contFn, f) {
1034
+ return defer_1(() => new tsplus_module_3.Sink(foldIOReader(z(), contFn, f)), fileName_1 + ":1061:20");
1035
+ }
1036
+
1037
+ function foldChunkSplitIO(s, contFn, f, chunk, idx, len) {
1038
+ if (idx === len) {
1039
+ return tsplus_module_9.succeedNow([s, tsplus_module_16.nothing()], fileName_1 + ":1073:25");
1040
+ } else {
1041
+ return tsplus_module_9.flatMap_(f(s, tsplus_module_2.unsafeGet_(chunk, idx)), s1 => {
1042
+ if (contFn(s1)) {
1043
+ return foldChunkSplitIO(s1, contFn, f, chunk, idx + 1, len);
1044
+ } else {
1045
+ return tsplus_module_9.succeedNow([s1, tsplus_module_16.just(tsplus_module_2.drop_(chunk, idx + 1))], fileName_1 + ":1079:29");
1046
+ }
1047
+ }, fileName_1 + ":1075:36");
1048
+ }
1049
+ }
1050
+
1051
+ function foldIOReader(s, contFn, f) {
1052
+ if (!contFn(s)) {
1053
+ return tsplus_module_5.succeedNow(s);
1054
+ } else {
1055
+ return tsplus_module_4.readWith(inp => tsplus_module_5.flatMap_(tsplus_module_4.fromIO(() => foldChunkSplitIO(s, contFn, f, inp, 0, inp.length)), ([nextS, leftovers]) => tsplus_module_22.match_(leftovers, () => foldIOReader(nextS, contFn, f), l => tsplus_module_4.as_(tsplus_module_4.writeNow(l), () => nextS))), err => tsplus_module_4.failNow(err), _ => tsplus_module_5.succeedNow(_));
1056
+ }
1057
+ }
1058
+ /**
1059
+ * Creates a sink that effectfully folds elements of type `In` into a
1060
+ * structure of type `S` until `max` elements have been folded.
1061
+ *
1062
+ * Like {@link makeFoldWeightedIO}, but with a constant cost function of 1.
1063
+ *
1064
+ * @tsplus static fncts.io.SinkOps foldUntilIO
1065
+ */
1066
+
1067
+
1068
+ function makeFoldUntilIO(z, max, f, __tsplusTrace) {
1069
+ return map_1(makeFoldIO_1(() => [z(), 0], ([_, n]) => n < max(), ([o, count], i) => tsplus_module_9.map_(f(o, i), s => [s, count + 1], __tsplusTrace)), ([s]) => s, __tsplusTrace);
1070
+ }
1071
+ /**
1072
+ * Creates a sink that folds elements of type `In` into a structure of type
1073
+ * `S`, until `max` worth of elements (determined by the `costFn`) have been
1074
+ * folded.
1075
+ *
1076
+ * The `decompose` function will be used for decomposing elements that cause
1077
+ * an `S` aggregate to cross `max` into smaller elements.
1078
+ *
1079
+ *
1080
+ * Be vigilant with this function, it has to generate "simpler" values or the
1081
+ * fold may never end. A value is considered indivisible if `decompose` yields
1082
+ * the empty chunk or a single-valued chunk. In these cases, there is no other
1083
+ * choice than to yield a value that will cross the threshold.
1084
+ *
1085
+ * The {@link makeFoldWeightedDecomposeIO} allows the decompose function to return a
1086
+ * `IO` value, and consequently it allows the sink to fail.
1087
+ *
1088
+ * @tsplus static fncts.io.SinkOps foldWeightedDecompose
1089
+ */
1090
+
1091
+
1092
+ function makeFoldWeightedDecompose_1(z, costFn, max, decompose, f, __tsplusTrace) {
1093
+ return defer_1(() => {
1094
+ /**
1095
+ * @tsplus tailRec
1096
+ */
1097
+ function fold(inp, s, max, dirty, cost, idx) {
1098
+ if (idx === inp.length) {
1099
+ return [s, cost, dirty, tsplus_module_1.empty()];
1100
+ } else {
1101
+ const elem = tsplus_module_2.unsafeGet_(inp, idx);
1102
+ const total = cost + costFn(s, elem);
1103
+
1104
+ if (total <= max) {
1105
+ return fold(inp, f(s, elem), max, true, total, idx + 1);
1106
+ } else {
1107
+ const decomposed = decompose(elem);
1108
+
1109
+ if (decomposed.length <= 1 && !dirty) {
1110
+ return [f(s, elem), total, true, tsplus_module_2.drop_(inp, idx + 1)];
1111
+ } else if (decomposed.length <= 1 && dirty) {
1112
+ return [s, cost, dirty, tsplus_module_2.drop_(inp, idx)];
1113
+ } else {
1114
+ return fold(tsplus_module_2.concat_(decomposed, tsplus_module_2.drop_(inp, idx + 1)), s, max, dirty, cost, 0);
1115
+ }
1116
+ }
1117
+ }
1118
+ }
1119
+
1120
+ function go(s, cost, dirty, max) {
1121
+ return tsplus_module_4.readWith(inp => {
1122
+ const [nextS, nextCost, nextDirty, leftovers] = fold(inp, s, max, dirty, cost, 0);
1123
+
1124
+ if (tsplus_module_2.isNonEmpty(leftovers)) {
1125
+ return tsplus_module_5.apSecond_(tsplus_module_4.writeNow(leftovers), tsplus_module_5.succeedNow(nextS));
1126
+ } else if (cost > max) {
1127
+ return tsplus_module_5.succeedNow(nextS);
1128
+ } else {
1129
+ return go(nextS, nextCost, nextDirty, max);
1130
+ }
1131
+ }, err => tsplus_module_4.failNow(err), _ => tsplus_module_5.succeedNow(s));
1132
+ }
1133
+
1134
+ return new tsplus_module_3.Sink(go(z(), 0, false, max()));
1135
+ }, __tsplusTrace);
1136
+ }
1137
+ /**
1138
+ * Creates a sink that effectfully folds elements of type `In` into a
1139
+ * structure of type `S`, until `max` worth of elements (determined by the
1140
+ * `costFn`) have been folded.
1141
+ *
1142
+ * The `decompose` function will be used for decomposing elements that cause
1143
+ * an `S` aggregate to cross `max` into smaller elements. Be vigilant with
1144
+ * this function, it has to generate "simpler" values or the fold may never
1145
+ * end. A value is considered indivisible if `decompose` yields the empty
1146
+ * chunk or a single-valued chunk. In these cases, there is no other choice
1147
+ * than to yield a value that will cross the threshold.
1148
+ *
1149
+ * @tsplus static fncts.io.SinkOps foldWeightedDecomposeIO
1150
+ */
1151
+
1152
+
1153
+ function makeFoldWeightedDecomposeIO_1(z, costFn, max, decompose, f, __tsplusTrace) {
1154
+ return defer_1(() => {
1155
+ function fold(inp, s, max, dirty, cost, idx) {
1156
+ if (idx === inp.length) {
1157
+ return tsplus_module_9.succeedNow([s, cost, dirty, tsplus_module_1.empty()], __tsplusTrace);
1158
+ } else {
1159
+ const elem = tsplus_module_2.unsafeGet_(inp, idx);
1160
+ return tsplus_module_9.flatMap_(tsplus_module_9.map_(costFn(s, elem), _ => cost + _, __tsplusTrace), total => {
1161
+ if (total <= max) {
1162
+ return tsplus_module_9.flatMap_(f(s, elem), s => fold(inp, s, max, true, total, idx + 1), __tsplusTrace);
1163
+ } else {
1164
+ return tsplus_module_9.flatMap_(decompose(elem), decomposed => {
1165
+ if (decomposed.length <= 1 && !dirty) {
1166
+ return tsplus_module_9.map_(f(s, elem), s => [s, total, true, tsplus_module_2.drop_(inp, idx + 1)], __tsplusTrace);
1167
+ } else if (decomposed.length <= 1 && dirty) {
1168
+ return tsplus_module_9.succeedNow([s, cost, dirty, tsplus_module_2.drop_(inp, idx)], __tsplusTrace);
1169
+ } else {
1170
+ return fold(tsplus_module_2.concat_(decomposed, tsplus_module_2.drop_(inp, idx + 1)), s, max, dirty, cost, 0);
1171
+ }
1172
+ }, __tsplusTrace);
1173
+ }
1174
+ }, __tsplusTrace);
1175
+ }
1176
+ }
1177
+
1178
+ function go(s, cost, dirty, max) {
1179
+ return tsplus_module_4.readWith(inp => tsplus_module_5.flatMap_(tsplus_module_4.fromIO(() => fold(inp, s, max, dirty, cost, 0)), ([nextS, nextCost, nextDirty, leftovers]) => {
1180
+ if (tsplus_module_2.isNonEmpty(leftovers)) {
1181
+ return tsplus_module_5.apSecond_(tsplus_module_4.writeNow(leftovers), tsplus_module_5.succeedNow(nextS));
1182
+ } else if (cost > max) {
1183
+ return tsplus_module_5.succeedNow(nextS);
1184
+ } else {
1185
+ return go(nextS, nextCost, nextDirty, max);
1186
+ }
1187
+ }), err => tsplus_module_4.failNow(err), _ => tsplus_module_5.succeedNow(s));
1188
+ }
1189
+
1190
+ return new tsplus_module_3.Sink(go(z(), 0, false, max()));
1191
+ }, __tsplusTrace);
1192
+ }
1193
+ /**
1194
+ * Creates a sink that folds elements of type `In` into a structure of type
1195
+ * `S`, until `max` worth of elements (determined by the `costFn`) have been
1196
+ * folded.
1197
+ *
1198
+ * @note
1199
+ * Elements that have an individual cost larger than `max` will force the
1200
+ * sink to cross the `max` cost. See {@link makeFoldWeightedDecompose} for a variant
1201
+ * that can handle these cases.
1202
+ *
1203
+ * @tsplus static fncts.io.SinkOps foldWeighted
1204
+ */
1205
+
1206
+
1207
+ function makeFoldWeighted(z, costFn, max, f, __tsplusTrace) {
1208
+ return makeFoldWeightedDecompose_1(z, costFn, max, tsplus_module_24.single, f, __tsplusTrace);
1209
+ }
1210
+ /**
1211
+ * Creates a sink that effectfully folds elements of type `In` into a
1212
+ * structure of type `S`, until `max` worth of elements (determined by the
1213
+ * `costFn`) have been folded.
1214
+ *
1215
+ * @note
1216
+ * Elements that have an individual cost larger than `max` will force the
1217
+ * sink to cross the `max` cost. See {@link makeFoldWeightedDecomposeIO} for a
1218
+ * variant that can handle these cases.
1219
+ *
1220
+ * @tsplus static fncts.io.SinkOps foldWeightedIO
1221
+ */
1222
+
1223
+
1224
+ function makeFoldWeightedIO(z, costFn, max, f, __tsplusTrace) {
1225
+ return makeFoldWeightedDecomposeIO_1(z, costFn, max, inp => tsplus_module_9.succeedNow(tsplus_module_24.single(inp), __tsplusTrace), f, __tsplusTrace);
1226
+ }
1227
+ /**
1228
+ * Transforms this sink's result.
1229
+ *
1230
+ * @tsplus fluent fncts.io.Sink map
1231
+ */
1232
+
1233
+
1234
+ function map_1(self, f, __tsplusTrace) {
1235
+ return new tsplus_module_3.Sink(tsplus_module_5.map_(self.channel, f));
1236
+ }
1237
+ /**
1238
+ * Transforms the errors emitted by this sink using `f`.
1239
+ *
1240
+ * @tsplus fluent fncts.io.Sink mapError
1241
+ */
1242
+
1243
+
1244
+ function mapError_(self, f, __tsplusTrace) {
1245
+ return new tsplus_module_3.Sink(tsplus_module_4.mapError_(self.channel, f));
1246
+ }
1247
+ /**
1248
+ * Effectfully transforms this sink's result.
1249
+ *
1250
+ * @tsplus fluent fncts.io.Sink mapIO
1251
+ */
1252
+
1253
+
1254
+ function mapIO_1(self, f, __tsplusTrace) {
1255
+ return new tsplus_module_3.Sink(tsplus_module_4.mapIO_(self.channel, f));
1256
+ }
1257
+ /**
1258
+ * Runs this sink until it yields a result, then uses that result to create
1259
+ * another sink from the provided function which will continue to run until it
1260
+ * yields a result.
1261
+ *
1262
+ * This function essentially runs sinks in sequence.
1263
+ *
1264
+ * @tsplus fluent fncts.io.Sink matchSink
1265
+ */
1266
+
1267
+
1268
+ function matchSink_1(self, onFailure, onSuccess, __tsplusTrace) {
1269
+ return new tsplus_module_3.Sink(tsplus_module_4.matchChannel_(tsplus_module_4.doneCollect(self.channel), e => onFailure(e).channel, ([leftovers, z]) => tsplus_module_4.defer(() => {
1270
+ const leftoversRef = new _AtomicReference.AtomicReference(tsplus_module_2.filter_(leftovers, c => tsplus_module_2.isNonEmpty(c)));
1271
+ const refReader = tsplus_module_5.flatMap_(tsplus_module_5.succeed(() => leftoversRef.getAndSet(tsplus_module_1.empty())), chunk => tsplus_module_4.writeChunk(chunk));
1272
+ const passthrough = tsplus_module_4.id();
1273
+ const continuationSink = tsplus_module_4.pipeTo_(tsplus_module_5.apSecond_(refReader, passthrough), onSuccess(z).channel);
1274
+ return tsplus_module_5.flatMap_(tsplus_module_4.doneCollect(continuationSink), ([newLeftovers, z1]) => tsplus_module_5.apSecond_(tsplus_module_5.flatMap_(tsplus_module_5.succeed(() => leftoversRef.get), tsplus_module_4.writeChunk), tsplus_module_4.as_(tsplus_module_4.writeChunk(newLeftovers), () => z1)));
1275
+ })));
1276
+ }
1277
+ /**
1278
+ * Switch to another sink in case of failure
1279
+ *
1280
+ * @tsplus fluent fncts.io.Sink orElse
1281
+ */
1282
+
1283
+
1284
+ function orElse(self, that, __tsplusTrace) {
1285
+ return defer_1(() => new tsplus_module_3.Sink(tsplus_module_4.orElse_(self.channel, that().channel)), __tsplusTrace);
1286
+ }
1287
+ /**
1288
+ * Provides the sink with its required environment, which eliminates its
1289
+ * dependency on `R`.
1290
+ *
1291
+ * @tsplus fluent fncts.io.Sink provideEnvironment
1292
+ */
1293
+
1294
+
1295
+ function provideEnvironment(self, r, __tsplusTrace) {
1296
+ return new tsplus_module_3.Sink(tsplus_module_4.provideEnvironment_(self.channel, r));
1297
+ }
1298
+ /**
1299
+ * Runs both sinks in parallel on the input, returning the result or the
1300
+ * error from the one that finishes first.
1301
+ *
1302
+ * @tsplus fluent fncts.io.Sink race
1303
+ */
1304
+
1305
+
1306
+ function race(self, that, __tsplusTrace) {
1307
+ return map_1(raceBoth_1(self, that), result => tsplus_module_25.merge(result), __tsplusTrace);
1308
+ }
1309
+ /**
1310
+ * Runs both sinks in parallel on the input, returning the result or the error
1311
+ * from the one that finishes first.
1312
+ *
1313
+ * @tsplus fluent fncts.io.Sink raceBoth
1314
+ */
1315
+
1316
+
1317
+ function raceBoth_1(self, that, capacity = () => 16, __tsplusTrace) {
1318
+ return raceWith_1(self, that, selfDone => tsplus_module_27.done(tsplus_module_9.map_(tsplus_module_9.fromExitNow(selfDone, __tsplusTrace), tsplus_module_26.left, __tsplusTrace)), thatDone => tsplus_module_27.done(tsplus_module_9.map_(tsplus_module_9.fromExitNow(thatDone, __tsplusTrace), tsplus_module_26.right, __tsplusTrace)), capacity, __tsplusTrace);
1319
+ }
1320
+ /**
1321
+ * Runs both sinks in parallel on the input, using the specified merge
1322
+ * function as soon as one result or the other has been computed.
1323
+ *
1324
+ * @tsplus fluent fncts.io.Sink raceWith
1325
+ */
1326
+
1327
+
1328
+ function raceWith_1(self, that, leftDone, rightDone, capacity = () => 16, __tsplusTrace) {
1329
+ const scoped = tsplus_module_9.defer(() => {
1330
+ const that0 = that();
1331
+ const capacity0 = capacity();
1332
+ return tsplus_module_9.flatMap_(tsplus_module_29.makeBounded(capacity()), hub => tsplus_module_9.flatMap_(tsplus_module_4.fromHubScoped(() => hub), c1 => tsplus_module_9.map_(tsplus_module_4.fromHubScoped(() => hub), c2 => {
1333
+ const reader = tsplus_module_4.toHub(() => hub);
1334
+ const writer = tsplus_module_28.mergeWith_(tsplus_module_4.pipeTo_(c1, self.channel), tsplus_module_4.pipeTo_(c2, that0.channel), leftDone, rightDone);
1335
+ const channel = tsplus_module_28.mergeWith_(reader, writer, () => tsplus_module_27.wait(tsplus_module_9.fromExitNow), done => tsplus_module_27.done(tsplus_module_9.fromExitNow(done, __tsplusTrace)));
1336
+ return new tsplus_module_3.Sink(channel);
1337
+ }, __tsplusTrace), __tsplusTrace), __tsplusTrace);
1338
+ }, __tsplusTrace);
1339
+ return unwrapScoped_1(() => scoped, __tsplusTrace);
1340
+ }
1341
+ /**
1342
+ * Accesses the specified service in the environment of the effect.
1343
+ *
1344
+ * @tsplus static fncts.io.SinkOps service
1345
+ */
1346
+
1347
+
1348
+ function service(
1349
+ /** @tsplus auto */
1350
+ tag) {
1351
+ const tag_1 = tag;
1352
+ return serviceWith_1(tsplus_module_14.identity, tag_1);
1353
+ }
1354
+ /**
1355
+ * Accesses the specified service in the environment of the sink.
1356
+ *
1357
+ * @tsplus static fncts.io.SinkOps serviceWith
1358
+ */
1359
+
1360
+
1361
+ function serviceWith_1(f,
1362
+ /** @tsplus auto */
1363
+ tag) {
1364
+ return fromIO_1(() => tsplus_module_13.serviceWith(f, tag), fileName_1 + ":1526:21");
1365
+ }
1366
+ /**
1367
+ * Accesses the specified service in the environment of the sink in the
1368
+ * context of an effect.
1369
+ *
1370
+ * @tsplus static fncts.io.SinkOps serviceWithIO
1371
+ */
1372
+
1373
+
1374
+ function serviceWithIO(f,
1375
+ /** @tsplus auto */
1376
+ tag) {
1377
+ return fromIO_1(() => tsplus_module_13.serviceWithIO(f, tag, fileName_1 + ":1539:38"), fileName_1 + ":1539:21");
1378
+ }
1379
+ /**
1380
+ * Accesses the specified service in the environment of the sink in the
1381
+ * context of a sink.
1382
+ *
1383
+ * @tsplus static fncts.io.SinkOps serviceWithSink
1384
+ */
1385
+
1386
+
1387
+ function serviceWithSink(f,
1388
+ /** @tsplus auto */
1389
+ tag) {
1390
+ return new tsplus_module_3.Sink(tsplus_module_4.unwrap(() => tsplus_module_13.serviceWith(tsplus_module_14.compose_(f, s => s.channel), tag)));
1391
+ }
1392
+ /**
1393
+ * Splits the sink on the specified predicate, returning a new sink that
1394
+ * consumes elements until an element after the first satisfies the specified
1395
+ * predicate.
1396
+ *
1397
+ * @tsplus fluent fncts.io.Sink splitWhere
1398
+ */
1399
+
1400
+
1401
+ function splitWhere(self, p, __tsplusTrace) {
1402
+ return new tsplus_module_3.Sink(tsplus_module_5.flatMap_(tsplus_module_4.fromIO(() => tsplus_module_8.make(() => tsplus_module_1.empty())), ref => tsplus_module_5.flatMap_(tsplus_module_4.collectElements(tsplus_module_4.pipeToOrFail_(splitter(p, false, ref), self.channel)), ([leftovers, z]) => tsplus_module_5.flatMap_(tsplus_module_4.fromIO(() => tsplus_module_7.get(ref)), leftover => tsplus_module_5.apSecond_(tsplus_module_4.writeNow(tsplus_module_2.concat_(leftover, tsplus_module_2.flatten(leftovers))), tsplus_module_5.succeedNow(z))))));
1403
+ }
1404
+
1405
+ function splitter(p, written, leftovers) {
1406
+ return tsplus_module_4.readWithCause(inp => {
1407
+ if (tsplus_module_2.isEmpty(inp)) {
1408
+ return splitter(p, written, leftovers);
1409
+ } else if (written) {
1410
+ const index = tsplus_module_30.findIndex(inp, p);
1411
+
1412
+ if (index === -1) {
1413
+ return tsplus_module_5.apSecond_(tsplus_module_4.writeNow(inp), splitter(p, true, leftovers));
1414
+ } else {
1415
+ const [left, right] = tsplus_module_2.splitAt_(inp, index);
1416
+ return tsplus_module_5.apSecond_(tsplus_module_4.writeNow(left), tsplus_module_4.fromIO(() => tsplus_module_6.set_(leftovers, right)));
1417
+ }
1418
+ } else {
1419
+ const index = tsplus_module_30.findIndex(inp, p);
1420
+
1421
+ if (index === -1) {
1422
+ return tsplus_module_5.apSecond_(tsplus_module_4.writeNow(inp), splitter(p, true, leftovers));
1423
+ } else {
1424
+ const [left, right] = tsplus_module_2.splitAt_(inp, Math.max(index, 1));
1425
+ return tsplus_module_5.apSecond_(tsplus_module_4.writeNow(left), tsplus_module_4.fromIO(() => tsplus_module_6.set_(leftovers, right)));
1426
+ }
1427
+ }
1428
+ }, tsplus_module_5.failCauseNow, tsplus_module_5.succeedNow);
1429
+ }
1430
+ /**
1431
+ * A sink that immediately ends with the specified value.
1432
+ *
1433
+ * @tsplus static fncts.io.SinkOps succeed
1434
+ */
1435
+
1436
+
1437
+ function succeed(z, __tsplusTrace) {
1438
+ return new tsplus_module_3.Sink(tsplus_module_5.succeed(z));
1439
+ }
1440
+ /**
1441
+ * A sink that immediately ends with the specified value.
1442
+ *
1443
+ * @tsplus static fncts.io.SinkOps succeedNow
1444
+ */
1445
+
1446
+
1447
+ function succeedNow(z, __tsplusTrace) {
1448
+ return new tsplus_module_3.Sink(tsplus_module_5.succeedNow(z));
1449
+ }
1450
+ /**
1451
+ * Summarize a sink by running an effect when the sink starts and again when
1452
+ * it completes
1453
+ *
1454
+ * @tsplus fluent fncts.io.Sink summarized
1455
+ */
1456
+
1457
+
1458
+ function summarized_1(self, summary, f, __tsplusTrace) {
1459
+ return new tsplus_module_3.Sink(tsplus_module_4.unwrap(() => tsplus_module_9.map_(tsplus_module_9.succeed(summary, __tsplusTrace), summary => tsplus_module_5.flatMap_(tsplus_module_4.fromIO(() => summary), start => tsplus_module_5.flatMap_(self.channel, done => tsplus_module_5.map_(tsplus_module_4.fromIO(() => summary), end => [done, f(start, end)]))), __tsplusTrace)));
1460
+ }
1461
+ /**
1462
+ * @tsplus getter fncts.io.Sink timed
1463
+ */
1464
+
1465
+
1466
+ function timed(self, __tsplusTrace) {
1467
+ return summarized_1(self, () => tsplus_module_31.currentTime, (start, end) => tsplus_module_32.fromInterval(start, end), __tsplusTrace);
1468
+ }
1469
+ /**
1470
+ * Creates a sink produced from an effect.
1471
+ *
1472
+ * @tsplus static fncts.io.SinkOps unwrap
1473
+ */
1474
+
1475
+
1476
+ function unwrap_1(io) {
1477
+ return new tsplus_module_3.Sink(tsplus_module_4.unwrap(() => tsplus_module_9.map_(io(), sink => sink.channel, fileName_1 + ":1678:42")));
1478
+ }
1479
+ /**
1480
+ * Creates a sink produced from a scoped effect.
1481
+ *
1482
+ * @tsplus static fncts.io.SinkOps unwrapScoped
1483
+ */
1484
+
1485
+
1486
+ function unwrapScoped_1(scoped, __tsplusTrace) {
1487
+ return new tsplus_module_3.Sink(tsplus_module_4.unwrapScoped(() => tsplus_module_9.map_(scoped(), sink => sink.channel, __tsplusTrace)));
1488
+ }
1489
+ /**
1490
+ * Feeds inputs to this sink until it yields a result, then switches over to
1491
+ * the provided sink until it yields a result, finally combining the two
1492
+ * results into a tuple.
1493
+ *
1494
+ * @tsplus fluent fncts.io.Sink zip
1495
+ */
1496
+
1497
+
1498
+ function zip(self, that, __tsplusTrace) {
1499
+ return zipWith_1(() => self, that, tsplus_module_14.tuple, __tsplusTrace);
1500
+ }
1501
+ /**
1502
+ * Runs both sinks in parallel on the input and combines the results in a
1503
+ * tuple.
1504
+ *
1505
+ * @tsplus fluent fncts.io.Sink zipC
1506
+ */
1507
+
1508
+
1509
+ function zipC(self, that, __tsplusTrace) {
1510
+ return zipWithC_1(() => self, that, tsplus_module_14.tuple, __tsplusTrace);
1511
+ }
1512
+ /**
1513
+ * Feeds inputs to this sink until it yields a result, then switches over to
1514
+ * the provided sink until it yields a result, finally combining the two
1515
+ * results with `f`.
1516
+ *
1517
+ * @tsplus fluent fncts.io.Sink zipWith
1518
+ */
1519
+
1520
+
1521
+ function zipWith_1(self, that, f, __tsplusTrace) {
1522
+ return defer_1(() => flatMap_1(self(), z => map_1(that(), z1 => f(z, z1), __tsplusTrace), __tsplusTrace), __tsplusTrace);
1523
+ }
1524
+ /**
1525
+ * Runs both sinks in parallel on the input and combines the results using the
1526
+ * provided function.
1527
+ *
1528
+ * @tsplus fluent fncts.io.Sink zipWithC
95
1529
  */
96
1530
 
97
1531
 
98
- function foreachWhile_1(f) {
99
- const process = tsplus_module_3.readWithCause(inp => foreachWhileLoop(f, inp, 0, inp.length, process), tsplus_module_2.failCauseNow, () => tsplus_module_3.unit);
100
- return new tsplus_module_4.Sink(process);
1532
+ function zipWithC_1(self, that, f, __tsplusTrace) {
1533
+ return defer_1(() => raceWith_1(self(), () => that(), exit => tsplus_module_33.match_(exit, err => tsplus_module_27.done(tsplus_module_9.failCauseNow(err, __tsplusTrace)), lz => tsplus_module_27.wait(exit => tsplus_module_33.match_(exit, cause => tsplus_module_9.failCauseNow(cause, __tsplusTrace), rz => tsplus_module_9.succeedNow(f(lz, rz), __tsplusTrace)))), exit => tsplus_module_33.match_(exit, err => tsplus_module_27.done(tsplus_module_9.failCauseNow(err, __tsplusTrace)), rz => tsplus_module_27.wait(exit => tsplus_module_33.match_(exit, cause => tsplus_module_9.failCauseNow(cause, __tsplusTrace), lz => tsplus_module_9.succeedNow(f(lz, rz), __tsplusTrace))))), __tsplusTrace);
101
1534
  }
102
1535
  //# sourceMappingURL=api.cjs.map