@fncts/io 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. package/Channel/api.d.ts +27 -4
  2. package/Channel/internal/MergeDecision.d.ts +14 -0
  3. package/STM/api.d.ts +7 -0
  4. package/Sink/api.d.ts +455 -7
  5. package/TReentrantLock/api.d.ts +97 -0
  6. package/TReentrantLock/definition.d.ts +65 -0
  7. package/TReentrantLock.d.ts +2 -0
  8. package/_cjs/Cached/api.cjs +1 -1
  9. package/_cjs/Cached/api.cjs.map +1 -1
  10. package/_cjs/Channel/api/mapOutIOC.cjs +1 -1
  11. package/_cjs/Channel/api/mapOutIOC.cjs.map +1 -1
  12. package/_cjs/Channel/api/mergeAllWith.cjs +2 -2
  13. package/_cjs/Channel/api/mergeAllWith.cjs.map +1 -1
  14. package/_cjs/Channel/api/mergeWith.cjs +1 -1
  15. package/_cjs/Channel/api/mergeWith.cjs.map +1 -1
  16. package/_cjs/Channel/api.cjs +87 -32
  17. package/_cjs/Channel/api.cjs.map +1 -1
  18. package/_cjs/Channel/internal/MergeDecision.cjs +11 -2
  19. package/_cjs/Channel/internal/MergeDecision.cjs.map +1 -1
  20. package/_cjs/IO/api/foreachC.cjs +2 -2
  21. package/_cjs/IO/api/foreachC.cjs.map +1 -1
  22. package/_cjs/STM/api.cjs +15 -6
  23. package/_cjs/STM/api.cjs.map +1 -1
  24. package/_cjs/Sink/api.cjs +1180 -40
  25. package/_cjs/Sink/api.cjs.map +1 -1
  26. package/_cjs/Stream/api.cjs +28 -28
  27. package/_cjs/Stream/api.cjs.map +1 -1
  28. package/_cjs/TReentrantLock/api.cjs +297 -0
  29. package/_cjs/TReentrantLock/api.cjs.map +1 -0
  30. package/_cjs/TReentrantLock/definition.cjs +125 -0
  31. package/_cjs/TReentrantLock/definition.cjs.map +1 -0
  32. package/_cjs/TReentrantLock.cjs +32 -0
  33. package/_cjs/TReentrantLock.cjs.map +1 -0
  34. package/_cjs/collection/immutable/Conc/filterIO.cjs +35 -0
  35. package/_cjs/collection/immutable/Conc/filterIO.cjs.map +1 -0
  36. package/_cjs/collection/immutable/Conc.cjs +13 -0
  37. package/_cjs/collection/immutable/Conc.cjs.map +1 -1
  38. package/_mjs/Cached/api.mjs +1 -1
  39. package/_mjs/Cached/api.mjs.map +1 -1
  40. package/_mjs/Channel/api/mapOutIOC.mjs +1 -1
  41. package/_mjs/Channel/api/mapOutIOC.mjs.map +1 -1
  42. package/_mjs/Channel/api/mergeAllWith.mjs +2 -2
  43. package/_mjs/Channel/api/mergeAllWith.mjs.map +1 -1
  44. package/_mjs/Channel/api/mergeWith.mjs +1 -1
  45. package/_mjs/Channel/api/mergeWith.mjs.map +1 -1
  46. package/_mjs/Channel/api.mjs +75 -30
  47. package/_mjs/Channel/api.mjs.map +1 -1
  48. package/_mjs/Channel/internal/MergeDecision.mjs +7 -0
  49. package/_mjs/Channel/internal/MergeDecision.mjs.map +1 -1
  50. package/_mjs/IO/api/foreachC.mjs +2 -2
  51. package/_mjs/IO/api/foreachC.mjs.map +1 -1
  52. package/_mjs/STM/api.mjs +13 -6
  53. package/_mjs/STM/api.mjs.map +1 -1
  54. package/_mjs/Sink/api.mjs +996 -31
  55. package/_mjs/Sink/api.mjs.map +1 -1
  56. package/_mjs/Stream/api.mjs +28 -28
  57. package/_mjs/Stream/api.mjs.map +1 -1
  58. package/_mjs/TReentrantLock/api.mjs +243 -0
  59. package/_mjs/TReentrantLock/api.mjs.map +1 -0
  60. package/_mjs/TReentrantLock/definition.mjs +102 -0
  61. package/_mjs/TReentrantLock/definition.mjs.map +1 -0
  62. package/_mjs/TReentrantLock.mjs +4 -0
  63. package/_mjs/TReentrantLock.mjs.map +1 -0
  64. package/_mjs/collection/immutable/Conc/filterIO.mjs +22 -0
  65. package/_mjs/collection/immutable/Conc/filterIO.mjs.map +1 -0
  66. package/_mjs/collection/immutable/Conc.mjs +1 -0
  67. package/_mjs/collection/immutable/Conc.mjs.map +1 -1
  68. package/_src/Channel/api.ts +98 -11
  69. package/_src/Channel/internal/MergeDecision.ts +15 -0
  70. package/_src/IO/api.ts +1 -1
  71. package/_src/STM/api.ts +9 -0
  72. package/_src/Sink/api.ts +1350 -19
  73. package/_src/TFuture/definition.ts +1 -1
  74. package/_src/TReentrantLock/api.ts +193 -0
  75. package/_src/TReentrantLock/definition.ts +86 -0
  76. package/_src/TReentrantLock.ts +4 -0
  77. package/_src/collection/immutable/Conc/filterIO.ts +16 -0
  78. package/_src/collection/immutable/Conc.ts +1 -0
  79. package/collection/immutable/Conc/filterIO.d.ts +7 -0
  80. package/collection/immutable/Conc.d.ts +1 -0
  81. package/package.json +3 -3
package/_mjs/Sink/api.mjs CHANGED
@@ -1,48 +1,458 @@
1
- import * as tsplus_module_1 from "@fncts/base/collection/immutable/Conc/api";
2
- import * as tsplus_module_2 from "@fncts/io/Channel/core-api";
3
- import * as tsplus_module_3 from "@fncts/io/Channel/api";
4
- import * as tsplus_module_4 from "@fncts/io/Sink/definition";
5
- import * as tsplus_module_5 from "@fncts/base/collection/immutable/Conc/api/empty";
6
- import * as tsplus_module_6 from "@fncts/io/IO/api";
7
- export const foreachWhile = foreachWhile_1;
1
+ const fileName_1 = "(@fncts/io) src/Sink/api.ts";
2
+ import * as tsplus_module_1 from "@fncts/base/collection/immutable/Conc/api/empty";
3
+ import * as tsplus_module_2 from "@fncts/base/collection/immutable/Conc/api";
4
+ import * as tsplus_module_3 from "@fncts/io/Sink/definition";
5
+ import * as tsplus_module_4 from "@fncts/io/Channel/api";
6
+ import * as tsplus_module_5 from "@fncts/io/Channel/core-api";
7
+ import * as tsplus_module_6 from "@fncts/io/Ref/api/set";
8
+ import * as tsplus_module_7 from "@fncts/io/Ref/api/get";
9
+ import * as tsplus_module_8 from "@fncts/io/Ref/constructors";
10
+ import * as tsplus_module_9 from "@fncts/io/IO/api";
11
+ import * as tsplus_module_10 from "@fncts/io/collection/immutable/Conc/mapIO";
12
+ import * as tsplus_module_11 from "@fncts/io/IO/api/environment";
13
+ import * as tsplus_module_12 from "@fncts/base/data/function/api";
14
+ import * as tsplus_module_13 from "@fncts/io/collection/immutable/Conc/filterIO";
15
+ import * as tsplus_module_14 from "@fncts/base/data/Maybe/constructors";
16
+ import * as tsplus_module_15 from "@fncts/base/data/Either/destructors";
17
+ import * as tsplus_module_16 from "@fncts/io/Queue/api/operations";
18
+ import * as tsplus_module_17 from "@fncts/io/IO/api/acquireRelease";
19
+ import * as tsplus_module_18 from "@fncts/base/data/Cause/api";
20
+ import * as tsplus_module_19 from "@fncts/base/data/Maybe/definition";
21
+ import * as tsplus_module_20 from "@fncts/base/data/Maybe/destructors";
22
+ import * as tsplus_module_21 from "@fncts/base/collection/immutable/Conc";
23
+ import * as tsplus_module_22 from "@fncts/base/collection/immutable/Conc/constructors";
24
+ import * as tsplus_module_23 from "@fncts/base/data/Either/api";
25
+ import * as tsplus_module_24 from "@fncts/base/data/Either/constructors";
26
+ import * as tsplus_module_25 from "@fncts/io/Channel/internal/MergeDecision";
27
+ import * as tsplus_module_26 from "@fncts/io/Channel/api/mergeWith";
28
+ import * as tsplus_module_27 from "@fncts/io/Hub/api";
29
+ import * as tsplus_module_28 from "@fncts/base/collection/Iterable/api";
30
+ import * as tsplus_module_29 from "@fncts/io/Clock/api";
31
+ import * as tsplus_module_30 from "@fncts/base/data/Duration/api";
32
+ import * as tsplus_module_31 from "@fncts/base/data/Exit/api";
33
+ export const collectAllWhileWith = collectAllWhileWith_1;
34
+ export const contramap = contramap_1;
35
+ export const contramapChunks = contramapChunks_1;
36
+ export const contramapChunksIO = contramapChunksIO_1;
37
+ export const contramapIO = contramapIO_1;
38
+ export const defer = defer_1;
39
+ export const failCause = failCause_1;
40
+ export const failCauseNow = failCauseNow_1;
41
+ export const failNow = failNow_1;
42
+ export const flatMap = flatMap_1;
43
+ export const fromQueue = fromQueue_1;
44
+ export const fromQueueWithShutdown = fromQueueWithShutdown_1;
45
+ export const fromIO = fromIO_1;
46
+ export const ignoreLeftover = ignoreLeftover_1;
47
+ export const makeForeachChunk = makeForeachChunk_1;
48
+ export const makeForeachWhile = makeForeachWhile_1;
49
+ export const makeFold = makeFold_1;
50
+ export const makeFoldUntil = makeFoldUntil_1;
51
+ export const makeFoldChunks = makeFoldChunks_1;
52
+ export const makeFoldChunksIO = makeFoldChunksIO_1;
53
+ export const makeFoldLeft = makeFoldLeft_1;
54
+ export const makeFoldIO = makeFoldIO_1;
55
+ export const makeFoldWeightedDecompose = makeFoldWeightedDecompose_1;
56
+ export const makeFoldWeightedDecomposeIO = makeFoldWeightedDecomposeIO_1;
57
+ export const map_ = map_1;
58
+ export const mapIO_ = mapIO_1;
59
+ export const matchSink_ = matchSink_1;
60
+ export const raceBoth = raceBoth_1;
61
+ export const raceWith = raceWith_1;
62
+ export const serviceWith = serviceWith_1;
63
+ export const summarized = summarized_1;
64
+ export const unwrap = unwrap_1;
65
+ export const unwrapScoped = unwrapScoped_1;
66
+ export const zipWith = zipWith_1;
67
+ export const zipWithC = zipWithC_1;
68
+ import { AtomicReference } from "@fncts/base/internal/AtomicReference";
69
+ /**
70
+ * @tsplus fluent fncts.io.Sink apFirst
71
+ */
8
72
 
9
- function collectLoop(state) {
10
- return tsplus_module_3.readWithCause(inp => collectLoop(tsplus_module_1.concat_(state, inp)), tsplus_module_2.failCauseNow, () => tsplus_module_2.endNow(state));
73
+ export function apFirst(self, that) {
74
+ return zipWith_1(() => self, that, (z, _) => z);
11
75
  }
12
76
  /**
13
- * A sink that collects all of its inputs into a chunk.
14
- *
15
- * @tsplus static fncts.io.SinkOps collectAll
77
+ * @tsplus fluent fncts.io.Sink apFirstC
78
+ */
79
+
80
+ export function apFirstC(self, that) {
81
+ return zipWithC_1(() => self, that, (z, _) => z);
82
+ }
83
+ /**
84
+ * @tsplus fluent fncts.io.Sink apSecond
85
+ */
86
+
87
+ export function apSecond(self, that) {
88
+ return zipWith_1(() => self, that, (_, z1) => z1);
89
+ }
90
+ /**
91
+ * @tsplus fluent fncts.io.Sink apSecondC
92
+ */
93
+
94
+ export function apSecondC(self, that) {
95
+ return zipWithC_1(() => self, that, (_, z1) => z1);
96
+ }
97
+ /**
98
+ * @tsplus fluent fncts.io.Sink as
99
+ */
100
+
101
+ export function as(self, z) {
102
+ return map_1(self, () => z(), fileName_1 + ":49:18");
103
+ }
104
+ /**
105
+ * @tsplus fluent fncts.io.Sink collectAll
106
+ */
107
+
108
+ export function collectAll(self, __tsplusTrace) {
109
+ return collectAllWhileWith_1(self, () => tsplus_module_1.empty(), () => true, (s, z) => tsplus_module_2.append_(s, z), __tsplusTrace);
110
+ }
111
+ /**
112
+ * @tsplus fluent fncts.io.Sink collectAllWhileWith
113
+ */
114
+
115
+ function collectAllWhileWith_1(self, z, p, f, __tsplusTrace) {
116
+ 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]) => {
117
+ 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));
118
+
119
+ function loop(currentResult) {
120
+ return tsplus_module_4.matchChannel_(tsplus_module_4.collectElements(self.channel), tsplus_module_4.failNow, ([leftovers, doneValue]) => {
121
+ if (p(doneValue)) {
122
+ 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 => {
123
+ const accumulatedResult = f(currentResult, doneValue);
124
+ if (upstreamDone) return tsplus_module_4.as_(tsplus_module_4.writeNow(tsplus_module_2.flatten(leftovers)), () => accumulatedResult);else return loop(accumulatedResult);
125
+ }));
126
+ } else {
127
+ return tsplus_module_4.as_(tsplus_module_4.writeNow(tsplus_module_2.flatten(leftovers)), () => currentResult);
128
+ }
129
+ });
130
+ }
131
+
132
+ return tsplus_module_4.pipeTo_(tsplus_module_4.pipeTo_(upstreamMarker, tsplus_module_4.bufferChunk(leftoversRef)), loop(z()));
133
+ }));
134
+ }
135
+ /**
136
+ * @tsplus getter fncts.io.Sink collectLeftover
137
+ */
138
+
139
+
140
+ export function collectLeftover(self, __tsplusTrace) {
141
+ return new tsplus_module_3.Sink(tsplus_module_5.map_(tsplus_module_4.collectElements(self.channel), ([chunks, z]) => [z, tsplus_module_2.flatten(chunks)]));
142
+ }
143
+ /**
144
+ * @tsplus fluent fncts.io.Sink contramap
145
+ */
146
+
147
+ function contramap_1(self, f) {
148
+ return contramapChunks_1(self, chunk => tsplus_module_2.map_(chunk, f));
149
+ }
150
+ /**
151
+ * @tsplus fluent fncts.io.Sink contramapChunks
152
+ */
153
+
154
+
155
+ function contramapChunks_1(self, f) {
156
+ 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);
157
+ return new tsplus_module_3.Sink(tsplus_module_4.pipeTo_(loop, self.channel));
158
+ }
159
+ /**
160
+ * @tsplus fluent fncts.io.Sink contramapChunksIO
161
+ */
162
+
163
+
164
+ function contramapChunksIO_1(self, f) {
165
+ 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);
166
+ return new tsplus_module_3.Sink(tsplus_module_4.pipeToOrFail_(loop, self.channel));
167
+ }
168
+ /**
169
+ * @tsplus fluent fncts.io.Sink contramapIO
170
+ */
171
+
172
+
173
+ function contramapIO_1(self, f) {
174
+ return contramapChunksIO_1(self, chunk => tsplus_module_10.mapIO_(chunk, f));
175
+ }
176
+ /**
177
+ * @tsplus fluent fncts.io.Sink dimap
178
+ */
179
+
180
+
181
+ export function dimap(self, f, g) {
182
+ return map_1(contramap_1(self, f), g, fileName_1 + ":171:31");
183
+ }
184
+ /**
185
+ * @tsplus fluent fncts.io.Sink dimapChunks
186
+ */
187
+
188
+ export function dimapChunks(self, f, g) {
189
+ return map_1(contramapChunks_1(self, f), g, fileName_1 + ":182:37");
190
+ }
191
+ /**
192
+ * @tsplus fluent fncts.io.Sink dimapChunksIO
193
+ */
194
+
195
+ export function dimapChunksIO(self, f, g) {
196
+ return mapIO_1(contramapChunksIO_1(self, f), g, fileName_1 + ":193:41");
197
+ }
198
+ /**
199
+ * @tsplus fluent fncts.io.Sink dimapIO
16
200
  */
17
201
 
202
+ export function dimapIO(self, f, g) {
203
+ return mapIO_1(contramapIO_1(self, f), g, fileName_1 + ":204:35");
204
+ }
205
+ /**
206
+ * @tsplus static fncts.io.SinkOps defer
207
+ */
18
208
 
19
- export function collectAll() {
20
- return new tsplus_module_4.Sink(collectLoop(tsplus_module_5.empty()));
209
+ function defer_1(sink) {
210
+ return new tsplus_module_3.Sink(tsplus_module_4.defer(() => sink().channel));
21
211
  }
22
- const drainLoop = /*#__PURE__*/tsplus_module_3.readWithCause(() => drainLoop, tsplus_module_2.failCauseNow, () => tsplus_module_3.unit);
212
+
213
+ const drainLoop = /*#__PURE__*/tsplus_module_4.readWithCause(() => drainLoop, tsplus_module_5.failCauseNow, () => tsplus_module_4.unit);
23
214
  /**
24
215
  * A sink that ignores all of its inputs.
25
216
  *
26
217
  * @tsplus static fncts.io.SinkOps drain
27
218
  */
28
219
 
29
- export const drain = /*#__PURE__*/new tsplus_module_4.Sink(drainLoop);
220
+ export const drain = /*#__PURE__*/new tsplus_module_3.Sink(drainLoop);
30
221
  /**
31
222
  * @tsplus static fncts.io.SinkOps dropWhile
32
223
  */
33
224
 
34
225
  export function dropWhile(predicate) {
35
- const loop = tsplus_module_3.readWith(inp => {
36
- const leftover = tsplus_module_1.dropWhile_(inp, predicate);
37
- const more = tsplus_module_1.isEmpty(leftover);
226
+ const loop = tsplus_module_4.readWith(inp => {
227
+ const leftover = tsplus_module_2.dropWhile_(inp, predicate);
228
+ const more = tsplus_module_2.isEmpty(leftover);
38
229
 
39
230
  if (more) {
40
231
  return loop;
41
232
  } else {
42
- return tsplus_module_2.apSecond_(tsplus_module_3.writeNow(leftover), tsplus_module_3.id());
233
+ return tsplus_module_5.apSecond_(tsplus_module_4.writeNow(leftover), tsplus_module_4.id());
43
234
  }
44
- }, tsplus_module_3.failNow, () => tsplus_module_3.unit);
45
- return new tsplus_module_4.Sink(loop);
235
+ }, tsplus_module_4.failNow, () => tsplus_module_4.unit);
236
+ return new tsplus_module_3.Sink(loop);
237
+ }
238
+ /**
239
+ * @tsplus static fncts.io.SinkOps environment
240
+ */
241
+
242
+ export function environment(__tsplusTrace) {
243
+ return fromIO_1(() => tsplus_module_11.environment(__tsplusTrace));
244
+ }
245
+ /**
246
+ * @tsplus static fncts.io.SinkOps environmentWith
247
+ */
248
+
249
+ export function environmentWith(f, __tsplusTrace) {
250
+ return fromIO_1(() => tsplus_module_11.environmentWith(f, __tsplusTrace));
251
+ }
252
+ /**
253
+ * @tsplus static fncts.io.SinkOps environmentWithIO
254
+ */
255
+
256
+ export function environmentWithIO(f, __tsplusTrace) {
257
+ return fromIO_1(() => tsplus_module_11.environmentWithIO(f, __tsplusTrace));
258
+ }
259
+ /**
260
+ * @tsplus static fncts.io.SinkOps environmentWithSink
261
+ */
262
+
263
+ export function environmentWithSink(f, __tsplusTrace) {
264
+ return new tsplus_module_3.Sink(tsplus_module_4.unwrap(() => tsplus_module_11.environmentWith(tsplus_module_12.compose_(f, s => s.channel), __tsplusTrace)));
265
+ }
266
+ /**
267
+ * @tsplus static fncts.io.SinkOps fail
268
+ */
269
+
270
+ export function fail(e) {
271
+ return new tsplus_module_3.Sink(tsplus_module_4.fail(e));
272
+ }
273
+ /**
274
+ * @tsplus static fncts.io.SinkOps failCause
275
+ */
276
+
277
+ function failCause_1(cause, __tsplusTrace) {
278
+ return new tsplus_module_3.Sink(tsplus_module_5.failCause(cause));
279
+ }
280
+ /**
281
+ * @tsplus static fncts.io.SinkOps failCauseNow
282
+ */
283
+
284
+
285
+ function failCauseNow_1(cause, __tsplusTrace) {
286
+ return new tsplus_module_3.Sink(tsplus_module_5.failCauseNow(cause));
287
+ }
288
+ /**
289
+ * @tsplus static fncts.io.SinkOps failNow
290
+ */
291
+
292
+
293
+ function failNow_1(e, __tsplusTrace) {
294
+ return new tsplus_module_3.Sink(tsplus_module_4.failNow(e));
295
+ }
296
+ /**
297
+ * @tsplus static fncts.io.SinkOps filterInput
298
+ */
299
+
300
+
301
+ export function filterInput(self, p, __tsplusTrace) {
302
+ return contramapChunks_1(self, chunk => tsplus_module_2.filter_(chunk, p));
303
+ }
304
+ /**
305
+ * @tsplus static fncts.io.SinkOps filterInputIO
306
+ */
307
+
308
+ export function filterInputIO(self, p, __tsplusTrace) {
309
+ return contramapChunksIO_1(self, chunk => tsplus_module_13.filterIO(chunk, p));
310
+ }
311
+ /**
312
+ * @tsplus fluent fncts.io.Sink findIO
313
+ */
314
+
315
+ export function findIO(self, f, __tsplusTrace) {
316
+ 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]) => {
317
+ 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));
318
+ 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 => {
319
+ if (satisfied) return tsplus_module_4.as_(tsplus_module_4.writeNow(tsplus_module_2.flatten(leftovers)), () => tsplus_module_14.just(doneValue));else if (upstreamDone) return tsplus_module_4.as_(tsplus_module_4.writeNow(tsplus_module_2.flatten(leftovers)), () => tsplus_module_14.nothing());else return loop;
320
+ }))));
321
+ return tsplus_module_4.pipeTo_(tsplus_module_4.pipeTo_(upstreamMarker, tsplus_module_4.bufferChunk(leftoversRef)), loop);
322
+ }));
323
+ }
324
+ /**
325
+ * @tsplus fluent fncts.io.Sink flatMap
326
+ */
327
+
328
+ function flatMap_1(self, f, __tsplusTrace) {
329
+ return matchSink_1(self, failNow_1, f, __tsplusTrace);
330
+ }
331
+ /**
332
+ * @tsplus static fncts.io.SinkOps fromChannel
333
+ * @tsplus static fncts.io.SinkOps __call
334
+ */
335
+
336
+
337
+ export function fromChannel(channel) {
338
+ return new tsplus_module_3.Sink(channel);
339
+ }
340
+ /**
341
+ * @tsplus static fncts.io.SinkOps fromPush
342
+ */
343
+
344
+ export function fromPush(push, __tsplusTrace) {
345
+ return new tsplus_module_3.Sink(tsplus_module_4.unwrapScoped(() => tsplus_module_9.map_(push, fromPushPull, __tsplusTrace)));
346
+ }
347
+
348
+ function fromPushPull(push) {
349
+ return tsplus_module_4.readWith(inp => tsplus_module_4.matchChannel_(tsplus_module_4.fromIO(() => push(tsplus_module_14.just(inp))), ([r, leftovers]) => tsplus_module_15.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_14.nothing())), ([r, leftovers]) => tsplus_module_15.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 + ":427:37"))));
350
+ }
351
+ /**
352
+ * @tsplus static fncts.io.SinkOps fromQueue
353
+ */
354
+
355
+
356
+ function fromQueue_1(queue) {
357
+ return unwrap_1(() => tsplus_module_9.map_(tsplus_module_9.succeed(queue, fileName_1 + ":436:32"), queue => makeForeachChunk_1(inp => tsplus_module_16.offerAll_(queue, inp), fileName_1 + ":436:72"), fileName_1 + ":436:43"));
358
+ }
359
+ /**
360
+ * @tsplus static fncts.io.SinkOps fromQueueWithShutdown
361
+ */
362
+
363
+
364
+ function fromQueueWithShutdown_1(queue) {
365
+ return unwrapScoped_1(() => tsplus_module_9.map_(tsplus_module_17.acquireRelease(() => tsplus_module_9.succeed(queue, fileName_1 + ":444:15"), queue => tsplus_module_16.shutdown(queue)), queue => fromQueue_1(() => queue), fileName_1 + ":446:11"));
366
+ }
367
+ /**
368
+ * @tsplus static fncts.io.SinkOps fromHub
369
+ */
370
+
371
+
372
+ export function fromHub(hub) {
373
+ return fromQueue_1(hub);
374
+ }
375
+ /**
376
+ * @tsplus static fncts.io.SinkOps fromHubWithShutdown
377
+ */
378
+
379
+ export function fromHubWithShutdown(hub) {
380
+ return fromQueueWithShutdown_1(hub);
381
+ }
382
+ /**
383
+ * @tsplus static fncts.io.SinkOps fromIO
384
+ */
385
+
386
+ function fromIO_1(b) {
387
+ return new tsplus_module_3.Sink(tsplus_module_4.fromIO(b));
388
+ }
389
+ /**
390
+ * @tsplus static fncts.io.SinkOps halt
391
+ */
392
+
393
+
394
+ export function halt(defect, __tsplusTrace) {
395
+ return failCause_1(() => tsplus_module_18.halt(defect()), __tsplusTrace);
396
+ }
397
+ /**
398
+ * @tsplus static fncts.io.SinkOps haltNow
399
+ */
400
+
401
+ export function haltNow(defect, __tsplusTrace) {
402
+ return failCauseNow_1(tsplus_module_18.halt(defect), __tsplusTrace);
403
+ }
404
+ /**
405
+ * @tsplus static fncts.io.SinkOps head
406
+ */
407
+
408
+ export function head(__tsplusTrace) {
409
+ return makeFold_1(() => tsplus_module_14.nothing(), elem => tsplus_module_19.isNothing(elem), (s, inp) => tsplus_module_20.match_(s, () => tsplus_module_14.just(inp), () => s), __tsplusTrace);
410
+ }
411
+ /**
412
+ * @tsplus getter fncts.io.Sink ignoreLeftover
413
+ */
414
+
415
+ function ignoreLeftover_1(self, __tsplusTrace) {
416
+ return new tsplus_module_3.Sink(tsplus_module_4.drain(self.channel));
417
+ }
418
+ /**
419
+ * @tsplus static fncts.io.SinkOps last
420
+ */
421
+
422
+
423
+ export function last(__tsplusTrace) {
424
+ return makeFoldLeft_1(() => tsplus_module_14.nothing(), (_, inp) => tsplus_module_14.just(inp));
425
+ }
426
+ /**
427
+ * @tsplus static fncts.io.SinkOps leftover
428
+ */
429
+
430
+ export function leftover(c, __tsplusTrace) {
431
+ return new tsplus_module_3.Sink(tsplus_module_4.write(c));
432
+ }
433
+ /**
434
+ * @tsplus static fncts.io.SinkOps log
435
+ */
436
+
437
+ export function log(message, __tsplusTrace) {
438
+ return fromIO_1(() => tsplus_module_9.log(message, __tsplusTrace));
439
+ }
440
+ /**
441
+ * A sink that collects all of its inputs into a chunk.
442
+ *
443
+ * @tsplus static fncts.io.SinkOps collectAll
444
+ */
445
+
446
+ export function makeCollectAll() {
447
+ return new tsplus_module_3.Sink(collectLoop(tsplus_module_1.empty()));
448
+ }
449
+
450
+ function collectLoop(state) {
451
+ return tsplus_module_4.readWithCause(inp => collectLoop(tsplus_module_2.concat_(state, inp)), tsplus_module_5.failCauseNow, () => tsplus_module_5.endNow(state));
452
+ }
453
+
454
+ export function makeCollectAllN(n) {
455
+ return flatMap_1(fromIO_1(() => tsplus_module_9.succeed(() => new tsplus_module_21.ConcBuilder(), fileName_1 + ":549:32")), builder => map_1(makeFoldUntil_1(() => builder, n, (builder, inp) => builder.append(inp), fileName_1 + ":550:19"), builder => builder.result(), fileName_1 + ":550:95"), fileName_1 + ":549:64");
46
456
  }
47
457
  /**
48
458
  * A sink that executes the provided effectful function for every element fed to it.
@@ -50,8 +460,28 @@ export function dropWhile(predicate) {
50
460
  * @tsplus static fncts.io.SinkOps foreach
51
461
  */
52
462
 
53
- export function foreach(f) {
54
- return foreachWhile_1(inp => tsplus_module_6.as_(f(inp), () => true));
463
+ export function makeForeach(f, __tsplusTrace) {
464
+ return makeForeachWhile_1(inp => tsplus_module_9.as_(f(inp), () => true), __tsplusTrace);
465
+ }
466
+ /**
467
+ * @tsplus static fncts.io.SinkOps foreachChunk
468
+ */
469
+
470
+ function makeForeachChunk_1(f, __tsplusTrace) {
471
+ 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);
472
+ return new tsplus_module_3.Sink(process);
473
+ }
474
+ /**
475
+ * A sink that executes the provided effectful function for every element fed to it
476
+ * until `f` evaluates to `false`.
477
+ *
478
+ * @tsplus static fncts.io.SinkOps foreachWhile
479
+ */
480
+
481
+
482
+ function makeForeachWhile_1(f, __tsplusTrace) {
483
+ const process = tsplus_module_4.readWithCause(inp => foreachWhileLoop(f, inp, 0, inp.length, process), tsplus_module_5.failCauseNow, () => tsplus_module_4.unit);
484
+ return new tsplus_module_3.Sink(process);
55
485
  }
56
486
 
57
487
  function foreachWhileLoop(f, chunk, idx, len, cont) {
@@ -59,18 +489,553 @@ function foreachWhileLoop(f, chunk, idx, len, cont) {
59
489
  return cont;
60
490
  }
61
491
 
62
- 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)));
492
+ 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)));
63
493
  }
64
494
  /**
65
- * A sink that executes the provided effectful function for every element fed to it
66
- * until `f` evaluates to `false`.
495
+ * @tsplus static fncts.io.SinkOps foreachChunkWhile
496
+ */
497
+
498
+
499
+ export function makeForeachChunkWhile(f, __tsplusTrace) {
500
+ 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);
501
+ return new tsplus_module_3.Sink(reader);
502
+ }
503
+ /**
504
+ * @tsplus static fncts.io.SinkOps fold
505
+ */
506
+
507
+ function makeFold_1(z, contFn, f, __tsplusTrace) {
508
+ return defer_1(() => new tsplus_module_3.Sink(foldReader(z(), contFn, f)));
509
+ }
510
+ /**
511
+ * @tsplus tailRec
512
+ */
513
+
514
+
515
+ function foldChunkSplit(contFn, f, s, chunk, idx, len) {
516
+ var contFn_1 = contFn,
517
+ f_1 = f,
518
+ s_1 = s,
519
+ chunk_1 = chunk,
520
+ idx_1 = idx,
521
+ len_1 = len;
522
+ var contFn_2 = contFn,
523
+ f_2 = f,
524
+ s_2 = s,
525
+ chunk_2 = chunk,
526
+ idx_2 = idx,
527
+ len_2 = len;
528
+
529
+ while (1) {
530
+ if (idx_1 === len_1) {
531
+ return [s_1, tsplus_module_1.empty()];
532
+ } else {
533
+ const s1 = f_1(s_1, tsplus_module_2.unsafeGet_(chunk_1, idx_1));
534
+
535
+ if (contFn_1(s1)) {
536
+ contFn_2 = contFn_1;
537
+ f_2 = f_1;
538
+ s_2 = s1;
539
+ chunk_2 = chunk_1;
540
+ idx_2 = idx_1 + 1;
541
+ len_2 = len_1;
542
+ contFn_1 = contFn_2;
543
+ f_1 = f_2;
544
+ s_1 = s_2;
545
+ chunk_1 = chunk_2;
546
+ idx_1 = idx_2;
547
+ len_1 = len_2;
548
+ continue;
549
+ } else {
550
+ return [s1, tsplus_module_2.drop_(chunk_1, idx_1 + 1)];
551
+ }
552
+ }
553
+ }
554
+ }
555
+
556
+ function foldReader(s, contFn, f) {
557
+ if (!contFn(s)) {
558
+ return tsplus_module_5.succeedNow(s);
559
+ } else {
560
+ return tsplus_module_4.readWith(inp => {
561
+ const [nextS, leftovers] = foldChunkSplit(contFn, f, s, inp, 0, inp.length);
562
+
563
+ if (tsplus_module_2.isNonEmpty(leftovers)) {
564
+ return tsplus_module_4.as_(tsplus_module_4.writeNow(leftovers), () => nextS);
565
+ } else {
566
+ return foldReader(nextS, contFn, f);
567
+ }
568
+ }, _ => tsplus_module_4.failNow(_), _ => tsplus_module_5.succeedNow(_));
569
+ }
570
+ }
571
+ /**
572
+ * @tsplus static fncts.io.SinkOps foldUntil
573
+ */
574
+
575
+
576
+ function makeFoldUntil_1(z, max, f, __tsplusTrace) {
577
+ 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));
578
+ }
579
+ /**
580
+ * @tsplus static fncts.io.SinkOps foldChunks
581
+ */
582
+
583
+
584
+ function makeFoldChunks_1(z, contFn, f) {
585
+ return defer_1(() => new tsplus_module_3.Sink(foldChunksReader(z(), contFn, f)));
586
+ }
587
+
588
+ function foldChunksReader(s, contFn, f) {
589
+ if (!contFn(s)) {
590
+ return tsplus_module_5.succeedNow(s);
591
+ } else {
592
+ return tsplus_module_4.readWith(inp => {
593
+ const nextS = f(s, inp);
594
+ return foldChunksReader(nextS, contFn, f);
595
+ }, err => tsplus_module_4.failNow(err), _ => tsplus_module_5.succeedNow(_));
596
+ }
597
+ }
598
+ /**
599
+ * @tsplus static fncts.io.SinkOps foldChunksIO
600
+ */
601
+
602
+
603
+ function makeFoldChunksIO_1(z, contFn, f) {
604
+ return defer_1(() => new tsplus_module_3.Sink(foldChunksIOReader(z(), contFn, f)));
605
+ }
606
+
607
+ function foldChunksIOReader(s, contFn, f) {
608
+ if (!contFn(s)) {
609
+ return tsplus_module_5.succeedNow(s);
610
+ } else {
611
+ 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(_));
612
+ }
613
+ }
614
+ /**
615
+ * @tsplus static fncts.io.SinkOps foldLeft
616
+ */
617
+
618
+
619
+ function makeFoldLeft_1(z, f) {
620
+ return ignoreLeftover_1(makeFold_1(z, () => true, f, fileName_1 + ":772:19"), fileName_1 + ":772:37");
621
+ }
622
+ /**
623
+ * @tsplus static fncts.io.SinkOps foldLeftChunks
624
+ */
625
+
626
+
627
+ export function makeFoldLeftChunks(z, f) {
628
+ return ignoreLeftover_1(makeFoldChunks_1(z, () => true, f), fileName_1 + ":782:43");
629
+ }
630
+ /**
631
+ * @tsplus static fncts.io.SinkOps foldLeftChunksIO
632
+ */
633
+
634
+ export function makeFoldLeftChunksIO(z, f) {
635
+ return makeFoldChunksIO_1(z, () => true, f);
636
+ }
637
+ /**
638
+ * @tsplus static fncts.io.SinkOps foldLeftIO
639
+ */
640
+
641
+ export function makeFoldLeftIO(z, f) {
642
+ return makeFoldIO_1(z, () => true, f);
643
+ }
644
+ /**
645
+ * @tsplus static fncts.io.SinkOps foldIO
646
+ */
647
+
648
+ function makeFoldIO_1(z, contFn, f) {
649
+ return defer_1(() => new tsplus_module_3.Sink(foldIOReader(z(), contFn, f)));
650
+ }
651
+
652
+ function foldChunkSplitIO(s, contFn, f, chunk, idx, len) {
653
+ if (idx === len) {
654
+ return tsplus_module_9.succeedNow([s, tsplus_module_14.nothing()], fileName_1 + ":822:25");
655
+ } else {
656
+ return tsplus_module_9.flatMap_(f(s, tsplus_module_2.unsafeGet_(chunk, idx)), s1 => {
657
+ if (contFn(s1)) {
658
+ return foldChunkSplitIO(s1, contFn, f, chunk, idx + 1, len);
659
+ } else {
660
+ return tsplus_module_9.succeedNow([s1, tsplus_module_14.just(tsplus_module_2.drop_(chunk, idx + 1))], fileName_1 + ":828:29");
661
+ }
662
+ }, fileName_1 + ":824:36");
663
+ }
664
+ }
665
+
666
+ function foldIOReader(s, contFn, f) {
667
+ if (!contFn(s)) {
668
+ return tsplus_module_5.succeedNow(s);
669
+ } else {
670
+ 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_20.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(_));
671
+ }
672
+ }
673
+ /**
674
+ * @tsplus static fncts.io.SinkOps foldUntilIO
675
+ */
676
+
677
+
678
+ export function makeFoldUntilIO(z, max, f) {
679
+ return map_1(makeFoldIO_1(() => [z(), 0], ([_, n]) => n < max(), ([o, count], i) => tsplus_module_9.map_(f(o, i), s => [s, count + 1], fileName_1 + ":867:35")), ([s]) => s, fileName_1 + ":868:8");
680
+ }
681
+ /**
682
+ * @tsplus static fncts.io.SinkOps foldWeightedDecompose
683
+ */
684
+
685
+ function makeFoldWeightedDecompose_1(z, costFn, max, decompose, f) {
686
+ return defer_1(() => {
687
+ /**
688
+ * @tsplus tailRec
689
+ */
690
+ function fold(inp, s, max, dirty, cost, idx) {
691
+ if (idx === inp.length) {
692
+ return [s, cost, dirty, tsplus_module_1.empty()];
693
+ } else {
694
+ const elem = tsplus_module_2.unsafeGet_(inp, idx);
695
+ const total = cost + costFn(s, elem);
696
+
697
+ if (total <= max) {
698
+ return fold(inp, f(s, elem), max, true, total, idx + 1);
699
+ } else {
700
+ const decomposed = decompose(elem);
701
+
702
+ if (decomposed.length <= 1 && !dirty) {
703
+ return [f(s, elem), total, true, tsplus_module_2.drop_(inp, idx + 1)];
704
+ } else if (decomposed.length <= 1 && dirty) {
705
+ return [s, cost, dirty, tsplus_module_2.drop_(inp, idx)];
706
+ } else {
707
+ return fold(tsplus_module_2.concat_(decomposed, tsplus_module_2.drop_(inp, idx + 1)), s, max, dirty, cost, 0);
708
+ }
709
+ }
710
+ }
711
+ }
712
+
713
+ function go(s, cost, dirty, max) {
714
+ return tsplus_module_4.readWith(inp => {
715
+ const [nextS, nextCost, nextDirty, leftovers] = fold(inp, s, max, dirty, cost, 0);
716
+
717
+ if (tsplus_module_2.isNonEmpty(leftovers)) {
718
+ return tsplus_module_5.apSecond_(tsplus_module_4.writeNow(leftovers), tsplus_module_5.succeedNow(nextS));
719
+ } else if (cost > max) {
720
+ return tsplus_module_5.succeedNow(nextS);
721
+ } else {
722
+ return go(nextS, nextCost, nextDirty, max);
723
+ }
724
+ }, err => tsplus_module_4.failNow(err), _ => tsplus_module_5.succeedNow(s));
725
+ }
726
+
727
+ return new tsplus_module_3.Sink(go(z(), 0, false, max()));
728
+ });
729
+ }
730
+ /**
731
+ * @tsplus static fncts.io.SinkOps foldWeightedDecomposeIO
732
+ */
733
+
734
+
735
+ function makeFoldWeightedDecomposeIO_1(z, costFn, max, decompose, f) {
736
+ return defer_1(() => {
737
+ function fold(inp, s, max, dirty, cost, idx) {
738
+ if (idx === inp.length) {
739
+ return tsplus_module_9.succeedNow([s, cost, dirty, tsplus_module_1.empty()], fileName_1 + ":961:29");
740
+ } else {
741
+ const elem = tsplus_module_2.unsafeGet_(inp, idx);
742
+ return tsplus_module_9.flatMap_(tsplus_module_9.map_(costFn(s, elem), _ => cost + _, fileName_1 + ":965:15"), total => {
743
+ if (total <= max) {
744
+ return tsplus_module_9.flatMap_(f(s, elem), s => fold(inp, s, max, true, total, idx + 1), fileName_1 + ":968:40");
745
+ } else {
746
+ return tsplus_module_9.flatMap_(decompose(elem), decomposed => {
747
+ if (decomposed.length <= 1 && !dirty) {
748
+ return tsplus_module_9.map_(f(s, elem), s => [s, total, true, tsplus_module_2.drop_(inp, idx + 1)], fileName_1 + ":972:40");
749
+ } else if (decomposed.length <= 1 && dirty) {
750
+ return tsplus_module_9.succeedNow([s, cost, dirty, tsplus_module_2.drop_(inp, idx)], fileName_1 + ":974:39");
751
+ } else {
752
+ return fold(tsplus_module_2.concat_(decomposed, tsplus_module_2.drop_(inp, idx + 1)), s, max, dirty, cost, 0);
753
+ }
754
+ }, fileName_1 + ":970:45");
755
+ }
756
+ }, fileName_1 + ":966:19");
757
+ }
758
+ }
759
+
760
+ function go(s, cost, dirty, max) {
761
+ 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]) => {
762
+ if (tsplus_module_2.isNonEmpty(leftovers)) {
763
+ return tsplus_module_5.apSecond_(tsplus_module_4.writeNow(leftovers), tsplus_module_5.succeedNow(nextS));
764
+ } else if (cost > max) {
765
+ return tsplus_module_5.succeedNow(nextS);
766
+ } else {
767
+ return go(nextS, nextCost, nextDirty, max);
768
+ }
769
+ }), err => tsplus_module_4.failNow(err), _ => tsplus_module_5.succeedNow(s));
770
+ }
771
+
772
+ return new tsplus_module_3.Sink(go(z(), 0, false, max()));
773
+ });
774
+ }
775
+ /**
776
+ * @tsplus static fncts.io.SinkOps foldWeighted
777
+ */
778
+
779
+
780
+ export function makeFoldWeighted(z, costFn, max, f) {
781
+ return makeFoldWeightedDecompose_1(z, costFn, max, tsplus_module_22.single, f);
782
+ }
783
+ /**
784
+ * @tsplus static fncts.io.SinkOps foldWeightedIO
785
+ */
786
+
787
+ export function makeFoldWeightedIO(z, costFn, max, f) {
788
+ return makeFoldWeightedDecomposeIO_1(z, costFn, max, inp => tsplus_module_9.succeedNow(tsplus_module_22.single(inp), fileName_1 + ":1030:77"), f);
789
+ }
790
+ /**
791
+ * Transforms this sink's result.
67
792
  *
68
- * @tsplus static fncts.io.SinkOps foreachWhile
793
+ * @tsplus fluent fncts.io.Sink map
794
+ */
795
+
796
+ function map_1(self, f, __tsplusTrace) {
797
+ return new tsplus_module_3.Sink(tsplus_module_5.map_(self.channel, f));
798
+ }
799
+ /**
800
+ * Transforms the errors emitted by this sink using `f`.
801
+ *
802
+ * @tsplus fluent fncts.io.Sink mapError
803
+ */
804
+
805
+
806
+ export function mapError_(self, f, __tsplusTrace) {
807
+ return new tsplus_module_3.Sink(tsplus_module_4.mapError_(self.channel, f));
808
+ }
809
+ /**
810
+ * Effectfully transforms this sink's result.
811
+ *
812
+ * @tsplus fluent fncts.io.Sink mapIO
813
+ */
814
+
815
+ function mapIO_1(self, f, __tsplusTrace) {
816
+ return new tsplus_module_3.Sink(tsplus_module_4.mapIO_(self.channel, f));
817
+ }
818
+ /**
819
+ * Runs this sink until it yields a result, then uses that result to create
820
+ * another sink from the provided function which will continue to run until it
821
+ * yields a result.
822
+ *
823
+ * This function essentially runs sinks in sequence.
824
+ *
825
+ * @tsplus fluent fncts.io.Sink matchSink
826
+ */
827
+
828
+
829
+ function matchSink_1(self, onFailure, onSuccess, __tsplusTrace) {
830
+ 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(() => {
831
+ const leftoversRef = new AtomicReference(tsplus_module_2.filter_(leftovers, c => tsplus_module_2.isNonEmpty(c)));
832
+ const refReader = tsplus_module_5.flatMap_(tsplus_module_5.succeed(() => leftoversRef.getAndSet(tsplus_module_1.empty())), chunk => tsplus_module_4.writeChunk(chunk));
833
+ const passthrough = tsplus_module_4.id();
834
+ const continuationSink = tsplus_module_4.pipeTo_(tsplus_module_5.apSecond_(refReader, passthrough), onSuccess(z).channel);
835
+ 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)));
836
+ })));
837
+ }
838
+ /**
839
+ * @tsplus fluent fncts.io.Sink orElse
840
+ */
841
+
842
+
843
+ export function orElse(self, that, __tsplusTrace) {
844
+ return defer_1(() => new tsplus_module_3.Sink(tsplus_module_4.orElse_(self.channel, that().channel)));
845
+ }
846
+ /**
847
+ * @tsplus fluent fncts.io.Sink provideEnvironment
848
+ */
849
+
850
+ export function provideEnvironment(self, r, __tsplusTrace) {
851
+ return new tsplus_module_3.Sink(tsplus_module_4.provideEnvironment_(self.channel, r));
852
+ }
853
+ /**
854
+ * @tsplus fluent fncts.io.Sink race
855
+ */
856
+
857
+ export function race(self, that) {
858
+ return map_1(raceBoth_1(self, that), result => tsplus_module_23.merge(result), fileName_1 + ":1136:33");
859
+ }
860
+ /**
861
+ * @tsplus fluent fncts.io.Sink raceBoth
862
+ */
863
+
864
+ function raceBoth_1(self, that, capacity = () => 16) {
865
+ return raceWith_1(self, that, selfDone => tsplus_module_25.done(tsplus_module_9.map_(tsplus_module_9.fromExitNow(selfDone, fileName_1 + ":1149:52"), tsplus_module_24.left, fileName_1 + ":1149:66")), thatDone => tsplus_module_25.done(tsplus_module_9.map_(tsplus_module_9.fromExitNow(thatDone, fileName_1 + ":1150:52"), tsplus_module_24.right, fileName_1 + ":1150:66")), capacity, fileName_1 + ":1147:23");
866
+ }
867
+ /**
868
+ * @tsplus fluent fncts.io.Sink raceWith
869
+ */
870
+
871
+
872
+ function raceWith_1(self, that, leftDone, rightDone, capacity = () => 16, __tsplusTrace) {
873
+ const scoped = tsplus_module_9.defer(() => {
874
+ const that0 = that();
875
+ const capacity0 = capacity();
876
+ return tsplus_module_9.flatMap_(tsplus_module_27.makeBounded(capacity()), hub => tsplus_module_9.flatMap_(tsplus_module_4.fromHubScoped(() => hub), c1 => tsplus_module_9.map_(tsplus_module_4.fromHubScoped(() => hub), c2 => {
877
+ const reader = tsplus_module_4.toHub(() => hub);
878
+ const writer = tsplus_module_26.mergeWith_(tsplus_module_4.pipeTo_(c1, self.channel), tsplus_module_4.pipeTo_(c2, that0.channel), leftDone, rightDone);
879
+ const channel = tsplus_module_26.mergeWith_(reader, writer, () => tsplus_module_25.wait(tsplus_module_9.fromExitNow), done => tsplus_module_25.done(tsplus_module_9.fromExitNow(done, __tsplusTrace)));
880
+ return new tsplus_module_3.Sink(channel);
881
+ }, __tsplusTrace), __tsplusTrace), __tsplusTrace);
882
+ }, __tsplusTrace);
883
+ return unwrapScoped_1(() => scoped);
884
+ }
885
+ /**
886
+ * @tsplus static fncts.io.SinkOps service
887
+ */
888
+
889
+
890
+ export function service(
891
+ /** @tsplus auto */
892
+ tag) {
893
+ const tag_1 = tag;
894
+ return serviceWith_1(tsplus_module_12.identity, tag_1);
895
+ }
896
+ /**
897
+ * @tsplus static fncts.io.SinkOps serviceWith
898
+ */
899
+
900
+ function serviceWith_1(f,
901
+ /** @tsplus auto */
902
+ tag) {
903
+ return fromIO_1(() => tsplus_module_11.serviceWith(f, tag));
904
+ }
905
+ /**
906
+ * @tsplus static fncts.io.SinkOps serviceWithIO
907
+ */
908
+
909
+
910
+ export function serviceWithIO(f,
911
+ /** @tsplus auto */
912
+ tag) {
913
+ return fromIO_1(() => tsplus_module_11.serviceWithIO(f, tag, fileName_1 + ":1210:38"));
914
+ }
915
+ /**
916
+ * @tsplus static fncts.io.SinkOps serviceWithSink
917
+ */
918
+
919
+ export function serviceWithSink(f,
920
+ /** @tsplus auto */
921
+ tag) {
922
+ return new tsplus_module_3.Sink(tsplus_module_4.unwrap(() => tsplus_module_11.serviceWith(tsplus_module_12.compose_(f, s => s.channel), tag)));
923
+ }
924
+ /**
925
+ * @tsplus fluent fncts.io.Sink splitWhere
926
+ */
927
+
928
+ export function splitWhere(self, p) {
929
+ 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))))));
930
+ }
931
+
932
+ function splitter(p, written, leftovers) {
933
+ return tsplus_module_4.readWithCause(inp => {
934
+ if (tsplus_module_2.isEmpty(inp)) {
935
+ return splitter(p, written, leftovers);
936
+ } else if (written) {
937
+ const index = tsplus_module_28.findIndex(inp, p);
938
+
939
+ if (index === -1) {
940
+ return tsplus_module_5.apSecond_(tsplus_module_4.writeNow(inp), splitter(p, true, leftovers));
941
+ } else {
942
+ const [left, right] = tsplus_module_2.splitAt_(inp, index);
943
+ return tsplus_module_5.apSecond_(tsplus_module_4.writeNow(left), tsplus_module_4.fromIO(() => tsplus_module_6.set_(leftovers, right)));
944
+ }
945
+ } else {
946
+ const index = tsplus_module_28.findIndex(inp, p);
947
+
948
+ if (index === -1) {
949
+ return tsplus_module_5.apSecond_(tsplus_module_4.writeNow(inp), splitter(p, true, leftovers));
950
+ } else {
951
+ const [left, right] = tsplus_module_2.splitAt_(inp, Math.max(index, 1));
952
+ return tsplus_module_5.apSecond_(tsplus_module_4.writeNow(left), tsplus_module_4.fromIO(() => tsplus_module_6.set_(leftovers, right)));
953
+ }
954
+ }
955
+ }, tsplus_module_5.failCauseNow, tsplus_module_5.succeedNow);
956
+ }
957
+ /**
958
+ * @tsplus static fncts.io.SinkOps succeed
959
+ */
960
+
961
+
962
+ export function succeed(z, __tsplusTrace) {
963
+ return new tsplus_module_3.Sink(tsplus_module_5.succeed(z));
964
+ }
965
+ /**
966
+ * @tsplus static fncts.io.SinkOps succeedNow
967
+ */
968
+
969
+ export function succeedNow(z, __tsplusTrace) {
970
+ return new tsplus_module_3.Sink(tsplus_module_5.succeedNow(z));
971
+ }
972
+ /**
973
+ * @tsplus fluent fncts.io.Sink summarized
974
+ */
975
+
976
+ function summarized_1(self, summary, f, __tsplusTrace) {
977
+ 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)));
978
+ }
979
+ /**
980
+ * @tsplus getter fncts.io.Sink timed
981
+ */
982
+
983
+
984
+ export function timed(self, __tsplusTrace) {
985
+ return summarized_1(self, () => tsplus_module_29.currentTime, (start, end) => tsplus_module_30.fromInterval(start, end), __tsplusTrace);
986
+ }
987
+ /**
988
+ * @tsplus static fncts.io.SinkOps unwrap
989
+ */
990
+
991
+ function unwrap_1(io) {
992
+ return new tsplus_module_3.Sink(tsplus_module_4.unwrap(() => tsplus_module_9.map_(io(), sink => sink.channel, fileName_1 + ":1332:42")));
993
+ }
994
+ /**
995
+ * Creates a sink produced from a scoped effect.
996
+ *
997
+ * @tsplus static fncts.io.SinkOps unwrapScoped
998
+ */
999
+
1000
+
1001
+ function unwrapScoped_1(scoped) {
1002
+ return new tsplus_module_3.Sink(tsplus_module_4.unwrapScoped(() => tsplus_module_9.map_(scoped(), sink => sink.channel, fileName_1 + ":1343:52")));
1003
+ }
1004
+ /**
1005
+ * @tsplus fluent fncts.io.Sink zip
1006
+ */
1007
+
1008
+
1009
+ export function zip(self, that) {
1010
+ return zipWith_1(() => self, that, tsplus_module_12.tuple);
1011
+ }
1012
+ /**
1013
+ * @tsplus fluent fncts.io.Sink zipC
1014
+ */
1015
+
1016
+ export function zipC(self, that) {
1017
+ return zipWithC_1(() => self, that, tsplus_module_12.tuple);
1018
+ }
1019
+ /**
1020
+ * Feeds inputs to this sink until it yields a result, then switches over to
1021
+ * the provided sink until it yields a result, finally combining the two
1022
+ * results with `f`.
1023
+ *
1024
+ * @tsplus fluent fncts.io.Sink zipWith
1025
+ */
1026
+
1027
+ function zipWith_1(self, that, f) {
1028
+ return defer_1(() => flatMap_1(self(), z => map_1(that(), z1 => f(z, z1), fileName_1 + ":1378:53"), fileName_1 + ":1378:35"));
1029
+ }
1030
+ /**
1031
+ * Runs both sinks in parallel on the input and combines the results using the
1032
+ * provided function.
1033
+ *
1034
+ * @tsplus fluent fncts.io.Sink zipWithC
69
1035
  */
70
1036
 
71
1037
 
72
- function foreachWhile_1(f) {
73
- const process = tsplus_module_3.readWithCause(inp => foreachWhileLoop(f, inp, 0, inp.length, process), tsplus_module_2.failCauseNow, () => tsplus_module_3.unit);
74
- return new tsplus_module_4.Sink(process);
1038
+ function zipWithC_1(self, that, f) {
1039
+ return defer_1(() => raceWith_1(self(), () => that(), exit => tsplus_module_31.match_(exit, err => tsplus_module_25.done(tsplus_module_9.failCauseNow(err, fileName_1 + ":1397:54")), lz => tsplus_module_25.wait(exit => tsplus_module_31.match_(exit, cause => tsplus_module_9.failCauseNow(cause, fileName_1 + ":1401:43"), rz => tsplus_module_9.succeedNow(f(lz, rz), fileName_1 + ":1402:38")))), exit => tsplus_module_31.match_(exit, err => tsplus_module_25.done(tsplus_module_9.failCauseNow(err, fileName_1 + ":1408:54")), rz => tsplus_module_25.wait(exit => tsplus_module_31.match_(exit, cause => tsplus_module_9.failCauseNow(cause, fileName_1 + ":1412:43"), lz => tsplus_module_9.succeedNow(f(lz, rz), fileName_1 + ":1413:38"))))));
75
1040
  }
76
1041
  //# sourceMappingURL=api.mjs.map