@fncts/io 0.0.10 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/_mjs/Sink/api.mjs CHANGED
@@ -9,27 +9,29 @@ import * as tsplus_module_7 from "@fncts/io/Ref/api/get";
9
9
  import * as tsplus_module_8 from "@fncts/io/Ref/constructors";
10
10
  import * as tsplus_module_9 from "@fncts/io/IO/api";
11
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";
12
+ import * as tsplus_module_11 from "@fncts/io/collection/immutable/Conc/dropUntilIO";
13
+ import * as tsplus_module_12 from "@fncts/io/collection/immutable/Conc/dropWhileIO";
14
+ import * as tsplus_module_13 from "@fncts/io/IO/api/environment";
15
+ import * as tsplus_module_14 from "@fncts/base/data/function/api";
16
+ import * as tsplus_module_15 from "@fncts/io/collection/immutable/Conc/filterIO";
17
+ import * as tsplus_module_16 from "@fncts/base/data/Maybe/constructors";
18
+ import * as tsplus_module_17 from "@fncts/base/data/Either/destructors";
19
+ import * as tsplus_module_18 from "@fncts/io/Queue/api/operations";
20
+ import * as tsplus_module_19 from "@fncts/io/IO/api/acquireRelease";
21
+ import * as tsplus_module_20 from "@fncts/base/data/Cause/api";
22
+ import * as tsplus_module_21 from "@fncts/base/data/Maybe/definition";
23
+ import * as tsplus_module_22 from "@fncts/base/data/Maybe/destructors";
24
+ import * as tsplus_module_23 from "@fncts/base/collection/immutable/Conc";
25
+ import * as tsplus_module_24 from "@fncts/base/collection/immutable/Conc/constructors";
26
+ import * as tsplus_module_25 from "@fncts/base/data/Either/api";
27
+ import * as tsplus_module_26 from "@fncts/base/data/Either/constructors";
28
+ import * as tsplus_module_27 from "@fncts/io/Channel/internal/MergeDecision";
29
+ import * as tsplus_module_28 from "@fncts/io/Channel/api/mergeWith";
30
+ import * as tsplus_module_29 from "@fncts/io/Hub/api";
31
+ import * as tsplus_module_30 from "@fncts/base/collection/Iterable/api";
32
+ import * as tsplus_module_31 from "@fncts/io/Clock/api";
33
+ import * as tsplus_module_32 from "@fncts/base/data/Duration/api";
34
+ import * as tsplus_module_33 from "@fncts/base/data/Exit/api";
33
35
  export const collectAllWhileWith = collectAllWhileWith_1;
34
36
  export const contramap = contramap_1;
35
37
  export const contramapChunks = contramapChunks_1;
@@ -67,41 +69,53 @@ export const zipWith = zipWith_1;
67
69
  export const zipWithC = zipWithC_1;
68
70
  import { AtomicReference } from "@fncts/base/internal/AtomicReference";
69
71
  /**
72
+ * Like {@link zip}, but keeps only the result from this sink
73
+ *
70
74
  * @tsplus fluent fncts.io.Sink apFirst
71
75
  */
72
76
 
73
77
  export function apFirst(self, that) {
74
- return zipWith_1(() => self, that, (z, _) => z);
78
+ return zipWith_1(() => self, that, (z, _) => z, fileName_1 + ":14:22");
75
79
  }
76
80
  /**
81
+ * Like {@link zipC}, but keeps only the result from this sink
82
+ *
77
83
  * @tsplus fluent fncts.io.Sink apFirstC
78
84
  */
79
85
 
80
86
  export function apFirstC(self, that) {
81
- return zipWithC_1(() => self, that, (z, _) => z);
87
+ return zipWithC_1(() => self, that, (z, _) => z, fileName_1 + ":26:23");
82
88
  }
83
89
  /**
90
+ * Like {@link zip}, but keeps only the result from the `that` sink
91
+ *
84
92
  * @tsplus fluent fncts.io.Sink apSecond
85
93
  */
86
94
 
87
- export function apSecond(self, that) {
88
- return zipWith_1(() => self, that, (_, z1) => z1);
95
+ export function apSecond(self, that, __tsplusTrace) {
96
+ return zipWith_1(() => self, that, (_, z1) => z1, __tsplusTrace);
89
97
  }
90
98
  /**
99
+ * Like {@link zipC}, but keeps only the result from the `that` sink
100
+ *
91
101
  * @tsplus fluent fncts.io.Sink apSecondC
92
102
  */
93
103
 
94
- export function apSecondC(self, that) {
95
- return zipWithC_1(() => self, that, (_, z1) => z1);
104
+ export function apSecondC(self, that, __tsplusTrace) {
105
+ return zipWithC_1(() => self, that, (_, z1) => z1, __tsplusTrace);
96
106
  }
97
107
  /**
108
+ * Replaces this sink's result with the provided value.
109
+ *
98
110
  * @tsplus fluent fncts.io.Sink as
99
111
  */
100
112
 
101
- export function as(self, z) {
102
- return map_1(self, () => z(), fileName_1 + ":49:18");
113
+ export function as(self, z, __tsplusTrace) {
114
+ return map_1(self, () => z(), __tsplusTrace);
103
115
  }
104
116
  /**
117
+ * Repeatedly runs the sink and accumulates its results into a chunk
118
+ *
105
119
  * @tsplus fluent fncts.io.Sink collectAll
106
120
  */
107
121
 
@@ -109,6 +123,10 @@ export function collectAll(self, __tsplusTrace) {
109
123
  return collectAllWhileWith_1(self, () => tsplus_module_1.empty(), () => true, (s, z) => tsplus_module_2.append_(s, z), __tsplusTrace);
110
124
  }
111
125
  /**
126
+ * Repeatedly runs the sink for as long as its results satisfy the predicate
127
+ * `p`. The sink's results will be accumulated using the stepping function
128
+ * `f`.
129
+ *
112
130
  * @tsplus fluent fncts.io.Sink collectAllWhileWith
113
131
  */
114
132
 
@@ -133,6 +151,9 @@ function collectAllWhileWith_1(self, z, p, f, __tsplusTrace) {
133
151
  }));
134
152
  }
135
153
  /**
154
+ * Collects the leftovers from the stream when the sink succeeds and returns
155
+ * them as part of the sink's result
156
+ *
136
157
  * @tsplus getter fncts.io.Sink collectLeftover
137
158
  */
138
159
 
@@ -141,72 +162,96 @@ export function collectLeftover(self, __tsplusTrace) {
141
162
  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
163
  }
143
164
  /**
165
+ * Transforms this sink's input elements.
166
+ *
144
167
  * @tsplus fluent fncts.io.Sink contramap
145
168
  */
146
169
 
147
- function contramap_1(self, f) {
148
- return contramapChunks_1(self, chunk => tsplus_module_2.map_(chunk, f));
170
+ function contramap_1(self, f, __tsplusTrace) {
171
+ return contramapChunks_1(self, chunk => tsplus_module_2.map_(chunk, f), __tsplusTrace);
149
172
  }
150
173
  /**
174
+ * Transforms this sink's input chunks. `f` must preserve chunking-invariance
175
+ *
151
176
  * @tsplus fluent fncts.io.Sink contramapChunks
152
177
  */
153
178
 
154
179
 
155
- function contramapChunks_1(self, f) {
180
+ function contramapChunks_1(self, f, __tsplusTrace) {
156
181
  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
182
  return new tsplus_module_3.Sink(tsplus_module_4.pipeTo_(loop, self.channel));
158
183
  }
159
184
  /**
185
+ * Effectfully transforms this sink's input chunks. `f` must preserve
186
+ * chunking-invariance
187
+ *
160
188
  * @tsplus fluent fncts.io.Sink contramapChunksIO
161
189
  */
162
190
 
163
191
 
164
- function contramapChunksIO_1(self, f) {
192
+ function contramapChunksIO_1(self, f, __tsplusTrace) {
165
193
  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
194
  return new tsplus_module_3.Sink(tsplus_module_4.pipeToOrFail_(loop, self.channel));
167
195
  }
168
196
  /**
197
+ * Effectfully transforms this sink's input elements.
198
+ *
169
199
  * @tsplus fluent fncts.io.Sink contramapIO
170
200
  */
171
201
 
172
202
 
173
- function contramapIO_1(self, f) {
174
- return contramapChunksIO_1(self, chunk => tsplus_module_10.mapIO_(chunk, f));
203
+ function contramapIO_1(self, f, __tsplusTrace) {
204
+ return contramapChunksIO_1(self, chunk => tsplus_module_10.mapIO_(chunk, f), __tsplusTrace);
175
205
  }
176
206
  /**
207
+ * Transforms both inputs and result of this sink using the provided
208
+ * functions.
209
+ *
177
210
  * @tsplus fluent fncts.io.Sink dimap
178
211
  */
179
212
 
180
213
 
181
- export function dimap(self, f, g) {
182
- return map_1(contramap_1(self, f), g, fileName_1 + ":171:31");
214
+ export function dimap(self, f, g, __tsplusTrace) {
215
+ return map_1(contramap_1(self, f, __tsplusTrace), g, __tsplusTrace);
183
216
  }
184
217
  /**
218
+ * Transforms both input chunks and result of this sink using the provided
219
+ * functions.
220
+ *
185
221
  * @tsplus fluent fncts.io.Sink dimapChunks
186
222
  */
187
223
 
188
- export function dimapChunks(self, f, g) {
189
- return map_1(contramapChunks_1(self, f), g, fileName_1 + ":182:37");
224
+ export function dimapChunks(self, f, g, __tsplusTrace) {
225
+ return map_1(contramapChunks_1(self, f, __tsplusTrace), g, __tsplusTrace);
190
226
  }
191
227
  /**
228
+ * Effectfully transforms both input chunks and result of this sink using the
229
+ * provided functions. `f` and `g` must preserve chunking-invariance
230
+ *
192
231
  * @tsplus fluent fncts.io.Sink dimapChunksIO
193
232
  */
194
233
 
195
- export function dimapChunksIO(self, f, g) {
196
- return mapIO_1(contramapChunksIO_1(self, f), g, fileName_1 + ":193:41");
234
+ export function dimapChunksIO(self, f, g, __tsplusTrace) {
235
+ return mapIO_1(contramapChunksIO_1(self, f, __tsplusTrace), g, __tsplusTrace);
197
236
  }
198
237
  /**
238
+ * Effectfully transforms both inputs and result of this sink using the
239
+ * provided functions.
240
+ *
199
241
  * @tsplus fluent fncts.io.Sink dimapIO
200
242
  */
201
243
 
202
- export function dimapIO(self, f, g) {
203
- return mapIO_1(contramapIO_1(self, f), g, fileName_1 + ":204:35");
244
+ export function dimapIO(self, f, g, __tsplusTrace) {
245
+ return mapIO_1(contramapIO_1(self, f, __tsplusTrace), g, __tsplusTrace);
204
246
  }
205
247
  /**
248
+ * Returns a lazily constructed sink that may require effects for its
249
+ * creation.
250
+ *
206
251
  * @tsplus static fncts.io.SinkOps defer
207
252
  */
208
253
 
209
- function defer_1(sink) {
254
+ function defer_1(sink, __tsplusTrace) {
210
255
  return new tsplus_module_3.Sink(tsplus_module_4.defer(() => sink().channel));
211
256
  }
212
257
 
@@ -219,10 +264,41 @@ const drainLoop = /*#__PURE__*/tsplus_module_4.readWithCause(() => drainLoop, ts
219
264
 
220
265
  export const drain = /*#__PURE__*/new tsplus_module_3.Sink(drainLoop);
221
266
  /**
267
+ * Drops incoming elements until the predicate `p` is satisfied.
268
+ *
269
+ * @tsplus static fncts.io.SinkOps dropUntil
270
+ */
271
+
272
+ export function makeDropUntil(p, __tsplusTrace) {
273
+ const loop = tsplus_module_4.readWith(inp => {
274
+ const leftover = tsplus_module_2.dropUntil(inp, p);
275
+ const more = tsplus_module_2.isEmpty(leftover);
276
+
277
+ if (more) {
278
+ return loop;
279
+ } else {
280
+ return tsplus_module_5.apSecond_(tsplus_module_4.writeNow(leftover), tsplus_module_4.id());
281
+ }
282
+ }, tsplus_module_4.failNow, () => tsplus_module_4.unit);
283
+ return new tsplus_module_3.Sink(loop);
284
+ }
285
+ /**
286
+ * Drops incoming elements until the effectful predicate `p` is satisfied.
287
+ *
288
+ * @tsplus static fncts.io.SinkOps dropUntilIO
289
+ */
290
+
291
+ export function makeDropUntilIO(p, __tsplusTrace) {
292
+ 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);
293
+ return new tsplus_module_3.Sink(loop);
294
+ }
295
+ /**
296
+ * Drops incoming elements as long as the predicate `p` is satisfied.
297
+ *
222
298
  * @tsplus static fncts.io.SinkOps dropWhile
223
299
  */
224
300
 
225
- export function dropWhile(predicate) {
301
+ export function makeDropWhile(predicate, __tsplusTrace) {
226
302
  const loop = tsplus_module_4.readWith(inp => {
227
303
  const leftover = tsplus_module_2.dropWhile_(inp, predicate);
228
304
  const more = tsplus_module_2.isEmpty(leftover);
@@ -236,41 +312,64 @@ export function dropWhile(predicate) {
236
312
  return new tsplus_module_3.Sink(loop);
237
313
  }
238
314
  /**
315
+ * Drops incoming elements as long as the effectful predicate `p` is
316
+ * satisfied.
317
+ *
318
+ * @tsplus static fncts.io.SinkOps dropWhileIO
319
+ */
320
+
321
+ export function dropWhileIO(p, __tsplusTrace) {
322
+ 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);
323
+ return new tsplus_module_3.Sink(loop);
324
+ }
325
+ /**
326
+ * Accesses the whole environment of the sink.
327
+ *
239
328
  * @tsplus static fncts.io.SinkOps environment
240
329
  */
241
330
 
242
331
  export function environment(__tsplusTrace) {
243
- return fromIO_1(() => tsplus_module_11.environment(__tsplusTrace));
332
+ return fromIO_1(() => tsplus_module_13.environment(__tsplusTrace), __tsplusTrace);
244
333
  }
245
334
  /**
335
+ * Accesses the environment of the sink.
336
+ *
246
337
  * @tsplus static fncts.io.SinkOps environmentWith
247
338
  */
248
339
 
249
340
  export function environmentWith(f, __tsplusTrace) {
250
- return fromIO_1(() => tsplus_module_11.environmentWith(f, __tsplusTrace));
341
+ return fromIO_1(() => tsplus_module_13.environmentWith(f, __tsplusTrace), __tsplusTrace);
251
342
  }
252
343
  /**
344
+ * Accesses the environment of the sink in the context of an effect.
345
+ *
253
346
  * @tsplus static fncts.io.SinkOps environmentWithIO
254
347
  */
255
348
 
256
349
  export function environmentWithIO(f, __tsplusTrace) {
257
- return fromIO_1(() => tsplus_module_11.environmentWithIO(f, __tsplusTrace));
350
+ return fromIO_1(() => tsplus_module_13.environmentWithIO(f, __tsplusTrace), __tsplusTrace);
258
351
  }
259
352
  /**
353
+ * Accesses the environment of the sink in the context of a sink.
354
+ *
260
355
  * @tsplus static fncts.io.SinkOps environmentWithSink
261
356
  */
262
357
 
263
358
  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)));
359
+ return new tsplus_module_3.Sink(tsplus_module_4.unwrap(() => tsplus_module_13.environmentWith(tsplus_module_14.compose_(f, s => s.channel), __tsplusTrace)));
265
360
  }
266
361
  /**
362
+ * A sink that always fails with the specified error.
363
+ *
267
364
  * @tsplus static fncts.io.SinkOps fail
268
365
  */
269
366
 
270
- export function fail(e) {
367
+ export function fail(e, __tsplusTrace) {
271
368
  return new tsplus_module_3.Sink(tsplus_module_4.fail(e));
272
369
  }
273
370
  /**
371
+ * Creates a sink halting with a specified cause.
372
+ *
274
373
  * @tsplus static fncts.io.SinkOps failCause
275
374
  */
276
375
 
@@ -278,6 +377,8 @@ function failCause_1(cause, __tsplusTrace) {
278
377
  return new tsplus_module_3.Sink(tsplus_module_5.failCause(cause));
279
378
  }
280
379
  /**
380
+ * Creates a sink halting with a specified cause.
381
+ *
281
382
  * @tsplus static fncts.io.SinkOps failCauseNow
282
383
  */
283
384
 
@@ -286,6 +387,8 @@ function failCauseNow_1(cause, __tsplusTrace) {
286
387
  return new tsplus_module_3.Sink(tsplus_module_5.failCauseNow(cause));
287
388
  }
288
389
  /**
390
+ * A sink that always fails with the specified error.
391
+ *
289
392
  * @tsplus static fncts.io.SinkOps failNow
290
393
  */
291
394
 
@@ -294,21 +397,27 @@ function failNow_1(e, __tsplusTrace) {
294
397
  return new tsplus_module_3.Sink(tsplus_module_4.failNow(e));
295
398
  }
296
399
  /**
400
+ * Filters the sink's input with the given predicate
401
+ *
297
402
  * @tsplus static fncts.io.SinkOps filterInput
298
403
  */
299
404
 
300
405
 
301
406
  export function filterInput(self, p, __tsplusTrace) {
302
- return contramapChunks_1(self, chunk => tsplus_module_2.filter_(chunk, p));
407
+ return contramapChunks_1(self, chunk => tsplus_module_2.filter_(chunk, p), __tsplusTrace);
303
408
  }
304
409
  /**
410
+ * Filters the sink's input with the given IO predicate
411
+ *
305
412
  * @tsplus static fncts.io.SinkOps filterInputIO
306
413
  */
307
414
 
308
415
  export function filterInputIO(self, p, __tsplusTrace) {
309
- return contramapChunksIO_1(self, chunk => tsplus_module_13.filterIO(chunk, p));
416
+ return contramapChunksIO_1(self, chunk => tsplus_module_15.filterIO(chunk, p), __tsplusTrace);
310
417
  }
311
418
  /**
419
+ * Creates a sink that produces values until one verifies the predicate `f`.
420
+ *
312
421
  * @tsplus fluent fncts.io.Sink findIO
313
422
  */
314
423
 
@@ -316,12 +425,18 @@ export function findIO(self, f, __tsplusTrace) {
316
425
  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
426
  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
427
  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;
428
+ 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;
320
429
  }))));
321
430
  return tsplus_module_4.pipeTo_(tsplus_module_4.pipeTo_(upstreamMarker, tsplus_module_4.bufferChunk(leftoversRef)), loop);
322
431
  }));
323
432
  }
324
433
  /**
434
+ * Runs this sink until it yields a result, then uses that result to create
435
+ * another sink from the provided function which will continue to run until it
436
+ * yields a result.
437
+ *
438
+ * This function essentially runs sinks in sequence.
439
+ *
325
440
  * @tsplus fluent fncts.io.Sink flatMap
326
441
  */
327
442
 
@@ -329,6 +444,8 @@ function flatMap_1(self, f, __tsplusTrace) {
329
444
  return matchSink_1(self, failNow_1, f, __tsplusTrace);
330
445
  }
331
446
  /**
447
+ * Creates a sink from a {@link Channel}
448
+ *
332
449
  * @tsplus static fncts.io.SinkOps fromChannel
333
450
  * @tsplus static fncts.io.SinkOps __call
334
451
  */
@@ -338,6 +455,8 @@ export function fromChannel(channel) {
338
455
  return new tsplus_module_3.Sink(channel);
339
456
  }
340
457
  /**
458
+ * Creates a sink from a chunk processing function.
459
+ *
341
460
  * @tsplus static fncts.io.SinkOps fromPush
342
461
  */
343
462
 
@@ -346,69 +465,89 @@ export function fromPush(push, __tsplusTrace) {
346
465
  }
347
466
 
348
467
  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"))));
468
+ 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"))));
350
469
  }
351
470
  /**
471
+ * Create a sink which enqueues each element into the specified queue.
472
+ *
352
473
  * @tsplus static fncts.io.SinkOps fromQueue
353
474
  */
354
475
 
355
476
 
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"));
477
+ function fromQueue_1(queue, __tsplusTrace) {
478
+ 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));
358
479
  }
359
480
  /**
481
+ * Create a sink which enqueues each element into the specified queue. The
482
+ * queue will be shutdown once the stream is closed.
483
+ *
360
484
  * @tsplus static fncts.io.SinkOps fromQueueWithShutdown
361
485
  */
362
486
 
363
487
 
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"));
488
+ function fromQueueWithShutdown_1(queue, __tsplusTrace) {
489
+ 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);
366
490
  }
367
491
  /**
492
+ * Create a sink which publishes each element to the specified hub.
493
+ *
368
494
  * @tsplus static fncts.io.SinkOps fromHub
369
495
  */
370
496
 
371
497
 
372
- export function fromHub(hub) {
373
- return fromQueue_1(hub);
498
+ export function fromHub(hub, __tsplusTrace) {
499
+ return fromQueue_1(hub, __tsplusTrace);
374
500
  }
375
501
  /**
502
+ * Create a sink which publishes each element to the specified hub. The hub
503
+ * will be shutdown once the stream is closed.
504
+ *
376
505
  * @tsplus static fncts.io.SinkOps fromHubWithShutdown
377
506
  */
378
507
 
379
- export function fromHubWithShutdown(hub) {
380
- return fromQueueWithShutdown_1(hub);
508
+ export function fromHubWithShutdown(hub, __tsplusTrace) {
509
+ return fromQueueWithShutdown_1(hub, __tsplusTrace);
381
510
  }
382
511
  /**
512
+ * Creates a single-value sink produced from an effect
513
+ *
383
514
  * @tsplus static fncts.io.SinkOps fromIO
384
515
  */
385
516
 
386
- function fromIO_1(b) {
517
+ function fromIO_1(b, __tsplusTrace) {
387
518
  return new tsplus_module_3.Sink(tsplus_module_4.fromIO(b));
388
519
  }
389
520
  /**
521
+ * Creates a sink halting with the specified unchecked value.
522
+ *
390
523
  * @tsplus static fncts.io.SinkOps halt
391
524
  */
392
525
 
393
526
 
394
527
  export function halt(defect, __tsplusTrace) {
395
- return failCause_1(() => tsplus_module_18.halt(defect()), __tsplusTrace);
528
+ return failCause_1(() => tsplus_module_20.halt(defect()), __tsplusTrace);
396
529
  }
397
530
  /**
531
+ * Creates a sink halting with the specified unchecked value.
532
+ *
398
533
  * @tsplus static fncts.io.SinkOps haltNow
399
534
  */
400
535
 
401
536
  export function haltNow(defect, __tsplusTrace) {
402
- return failCauseNow_1(tsplus_module_18.halt(defect), __tsplusTrace);
537
+ return failCauseNow_1(tsplus_module_20.halt(defect), __tsplusTrace);
403
538
  }
404
539
  /**
540
+ * Creates a sink containing the first value.
541
+ *
405
542
  * @tsplus static fncts.io.SinkOps head
406
543
  */
407
544
 
408
545
  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);
546
+ 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);
410
547
  }
411
548
  /**
549
+ * Drains the remaining elements from the stream after the sink finishes
550
+ *
412
551
  * @tsplus getter fncts.io.Sink ignoreLeftover
413
552
  */
414
553
 
@@ -416,14 +555,19 @@ function ignoreLeftover_1(self, __tsplusTrace) {
416
555
  return new tsplus_module_3.Sink(tsplus_module_4.drain(self.channel));
417
556
  }
418
557
  /**
558
+ * Creates a sink containing the last value.
559
+ *
419
560
  * @tsplus static fncts.io.SinkOps last
420
561
  */
421
562
 
422
563
 
423
564
  export function last(__tsplusTrace) {
424
- return makeFoldLeft_1(() => tsplus_module_14.nothing(), (_, inp) => tsplus_module_14.just(inp));
565
+ return makeFoldLeft_1(() => tsplus_module_16.nothing(), (_, inp) => tsplus_module_16.just(inp));
425
566
  }
426
567
  /**
568
+ * Creates a sink that does not consume any input but provides the given chunk
569
+ * as its leftovers
570
+ *
427
571
  * @tsplus static fncts.io.SinkOps leftover
428
572
  */
429
573
 
@@ -431,11 +575,13 @@ export function leftover(c, __tsplusTrace) {
431
575
  return new tsplus_module_3.Sink(tsplus_module_4.write(c));
432
576
  }
433
577
  /**
578
+ * Logs the specified message at the current log level.
579
+ *
434
580
  * @tsplus static fncts.io.SinkOps log
435
581
  */
436
582
 
437
583
  export function log(message, __tsplusTrace) {
438
- return fromIO_1(() => tsplus_module_9.log(message, __tsplusTrace));
584
+ return fromIO_1(() => tsplus_module_9.log(message, __tsplusTrace), __tsplusTrace);
439
585
  }
440
586
  /**
441
587
  * A sink that collects all of its inputs into a chunk.
@@ -450,9 +596,16 @@ export function makeCollectAll() {
450
596
  function collectLoop(state) {
451
597
  return tsplus_module_4.readWithCause(inp => collectLoop(tsplus_module_2.concat_(state, inp)), tsplus_module_5.failCauseNow, () => tsplus_module_5.endNow(state));
452
598
  }
599
+ /**
600
+ * A sink that collects first `n` elements into a chunk. Note that the chunk
601
+ * is preallocated and must fit in memory.
602
+ *
603
+ * @tsplus static fncts.io.SinkOps collectAllN
604
+ */
605
+
453
606
 
454
607
  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");
608
+ 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");
456
609
  }
457
610
  /**
458
611
  * A sink that executes the provided effectful function for every element fed to it.
@@ -464,6 +617,9 @@ export function makeForeach(f, __tsplusTrace) {
464
617
  return makeForeachWhile_1(inp => tsplus_module_9.as_(f(inp), () => true), __tsplusTrace);
465
618
  }
466
619
  /**
620
+ * A sink that executes the provided effectful function for every chunk fed to
621
+ * it.
622
+ *
467
623
  * @tsplus static fncts.io.SinkOps foreachChunk
468
624
  */
469
625
 
@@ -492,6 +648,9 @@ function foreachWhileLoop(f, chunk, idx, len, cont) {
492
648
  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)));
493
649
  }
494
650
  /**
651
+ * A sink that executes the provided effectful function for every chunk fed to
652
+ * it until `f` evaluates to `false`.
653
+ *
495
654
  * @tsplus static fncts.io.SinkOps foreachChunkWhile
496
655
  */
497
656
 
@@ -501,11 +660,14 @@ export function makeForeachChunkWhile(f, __tsplusTrace) {
501
660
  return new tsplus_module_3.Sink(reader);
502
661
  }
503
662
  /**
663
+ * A sink that folds its inputs with the provided function, termination
664
+ * predicate and initial state.
665
+ *
504
666
  * @tsplus static fncts.io.SinkOps fold
505
667
  */
506
668
 
507
669
  function makeFold_1(z, contFn, f, __tsplusTrace) {
508
- return defer_1(() => new tsplus_module_3.Sink(foldReader(z(), contFn, f)));
670
+ return defer_1(() => new tsplus_module_3.Sink(foldReader(z(), contFn, f)), __tsplusTrace);
509
671
  }
510
672
  /**
511
673
  * @tsplus tailRec
@@ -569,6 +731,11 @@ function foldReader(s, contFn, f) {
569
731
  }
570
732
  }
571
733
  /**
734
+ * Creates a sink that folds elements of type `In` into a structure of type
735
+ * `S` until `max` elements have been folded.
736
+ *
737
+ * Like {@link foldWeighted}, but with a constant cost function of 1.
738
+ *
572
739
  * @tsplus static fncts.io.SinkOps foldUntil
573
740
  */
574
741
 
@@ -577,12 +744,17 @@ function makeFoldUntil_1(z, max, f, __tsplusTrace) {
577
744
  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
745
  }
579
746
  /**
747
+ * A sink that folds its input chunks with the provided function, termination
748
+ * predicate and initial state. `contFn` condition is checked only for the
749
+ * initial value and at the end of processing of each chunk. `f` and `contFn`
750
+ * must preserve chunking-invariance.
751
+ *
580
752
  * @tsplus static fncts.io.SinkOps foldChunks
581
753
  */
582
754
 
583
755
 
584
- function makeFoldChunks_1(z, contFn, f) {
585
- return defer_1(() => new tsplus_module_3.Sink(foldChunksReader(z(), contFn, f)));
756
+ function makeFoldChunks_1(z, contFn, f, __tsplusTrace) {
757
+ return defer_1(() => new tsplus_module_3.Sink(foldChunksReader(z(), contFn, f)), __tsplusTrace);
586
758
  }
587
759
 
588
760
  function foldChunksReader(s, contFn, f) {
@@ -596,12 +768,17 @@ function foldChunksReader(s, contFn, f) {
596
768
  }
597
769
  }
598
770
  /**
771
+ * A sink that effectfully folds its input chunks with the provided function,
772
+ * termination predicate and initial state. `contFn` condition is checked only
773
+ * for the initial value and at the end of processing of each chunk. `f` and
774
+ * `contFn` must preserve chunking-invariance.
775
+ *
599
776
  * @tsplus static fncts.io.SinkOps foldChunksIO
600
777
  */
601
778
 
602
779
 
603
- function makeFoldChunksIO_1(z, contFn, f) {
604
- return defer_1(() => new tsplus_module_3.Sink(foldChunksIOReader(z(), contFn, f)));
780
+ function makeFoldChunksIO_1(z, contFn, f, __tsplusTrace) {
781
+ return defer_1(() => new tsplus_module_3.Sink(foldChunksIOReader(z(), contFn, f)), __tsplusTrace);
605
782
  }
606
783
 
607
784
  function foldChunksIOReader(s, contFn, f) {
@@ -612,54 +789,68 @@ function foldChunksIOReader(s, contFn, f) {
612
789
  }
613
790
  }
614
791
  /**
792
+ * A sink that folds its inputs with the provided function and initial state.
793
+ *
615
794
  * @tsplus static fncts.io.SinkOps foldLeft
616
795
  */
617
796
 
618
797
 
619
798
  function makeFoldLeft_1(z, f) {
620
- return ignoreLeftover_1(makeFold_1(z, () => true, f, fileName_1 + ":772:19"), fileName_1 + ":772:37");
799
+ return ignoreLeftover_1(makeFold_1(z, () => true, f, fileName_1 + ":1006:19"), fileName_1 + ":1006:37");
621
800
  }
622
801
  /**
802
+ * A sink that folds its input chunks with the provided function and initial
803
+ * state. `f` must preserve chunking-invariance.
804
+ *
623
805
  * @tsplus static fncts.io.SinkOps foldLeftChunks
624
806
  */
625
807
 
626
808
 
627
809
  export function makeFoldLeftChunks(z, f) {
628
- return ignoreLeftover_1(makeFoldChunks_1(z, () => true, f), fileName_1 + ":782:43");
810
+ return ignoreLeftover_1(makeFoldChunks_1(z, () => true, f, fileName_1 + ":1019:25"), fileName_1 + ":1019:43");
629
811
  }
630
812
  /**
813
+ * A sink that effectfully folds its input chunks with the provided function
814
+ * and initial state. `f` must preserve chunking-invariance.
815
+ *
631
816
  * @tsplus static fncts.io.SinkOps foldLeftChunksIO
632
817
  */
633
818
 
634
- export function makeFoldLeftChunksIO(z, f) {
635
- return makeFoldChunksIO_1(z, () => true, f);
819
+ export function makeFoldLeftChunksIO(z, f, __tsplusTrace) {
820
+ return makeFoldChunksIO_1(z, () => true, f, __tsplusTrace);
636
821
  }
637
822
  /**
823
+ * A sink that effectfully folds its inputs with the provided function and
824
+ * initial state.
825
+ *
638
826
  * @tsplus static fncts.io.SinkOps foldLeftIO
639
827
  */
640
828
 
641
- export function makeFoldLeftIO(z, f) {
829
+ export function makeFoldLeftIO(z, f, __tsplusTrace) {
642
830
  return makeFoldIO_1(z, () => true, f);
643
831
  }
644
832
  /**
833
+ * A sink that effectfully folds its inputs with the provided function,
834
+ * termination predicate and initial state.
835
+ *
645
836
  * @tsplus static fncts.io.SinkOps foldIO
646
837
  */
647
838
 
648
839
  function makeFoldIO_1(z, contFn, f) {
649
- return defer_1(() => new tsplus_module_3.Sink(foldIOReader(z(), contFn, f)));
840
+ return defer_1(() => new tsplus_module_3.Sink(foldIOReader(z(), contFn, f)), fileName_1 + ":1061:20");
650
841
  }
651
842
 
652
843
  function foldChunkSplitIO(s, contFn, f, chunk, idx, len) {
653
844
  if (idx === len) {
654
- return tsplus_module_9.succeedNow([s, tsplus_module_14.nothing()], fileName_1 + ":822:25");
845
+ return tsplus_module_9.succeedNow([s, tsplus_module_16.nothing()], fileName_1 + ":1073:25");
655
846
  } else {
656
847
  return tsplus_module_9.flatMap_(f(s, tsplus_module_2.unsafeGet_(chunk, idx)), s1 => {
657
848
  if (contFn(s1)) {
658
849
  return foldChunkSplitIO(s1, contFn, f, chunk, idx + 1, len);
659
850
  } else {
660
- return tsplus_module_9.succeedNow([s1, tsplus_module_14.just(tsplus_module_2.drop_(chunk, idx + 1))], fileName_1 + ":828:29");
851
+ return tsplus_module_9.succeedNow([s1, tsplus_module_16.just(tsplus_module_2.drop_(chunk, idx + 1))], fileName_1 + ":1079:29");
661
852
  }
662
- }, fileName_1 + ":824:36");
853
+ }, fileName_1 + ":1075:36");
663
854
  }
664
855
  }
665
856
 
@@ -667,22 +858,43 @@ function foldIOReader(s, contFn, f) {
667
858
  if (!contFn(s)) {
668
859
  return tsplus_module_5.succeedNow(s);
669
860
  } 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(_));
861
+ 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(_));
671
862
  }
672
863
  }
673
864
  /**
865
+ * Creates a sink that effectfully folds elements of type `In` into a
866
+ * structure of type `S` until `max` elements have been folded.
867
+ *
868
+ * Like {@link makeFoldWeightedIO}, but with a constant cost function of 1.
869
+ *
674
870
  * @tsplus static fncts.io.SinkOps foldUntilIO
675
871
  */
676
872
 
677
873
 
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");
874
+ export function makeFoldUntilIO(z, max, f, __tsplusTrace) {
875
+ 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);
680
876
  }
681
877
  /**
878
+ * Creates a sink that folds elements of type `In` into a structure of type
879
+ * `S`, until `max` worth of elements (determined by the `costFn`) have been
880
+ * folded.
881
+ *
882
+ * The `decompose` function will be used for decomposing elements that cause
883
+ * an `S` aggregate to cross `max` into smaller elements.
884
+ *
885
+ *
886
+ * Be vigilant with this function, it has to generate "simpler" values or the
887
+ * fold may never end. A value is considered indivisible if `decompose` yields
888
+ * the empty chunk or a single-valued chunk. In these cases, there is no other
889
+ * choice than to yield a value that will cross the threshold.
890
+ *
891
+ * The {@link makeFoldWeightedDecomposeIO} allows the decompose function to return a
892
+ * `IO` value, and consequently it allows the sink to fail.
893
+ *
682
894
  * @tsplus static fncts.io.SinkOps foldWeightedDecompose
683
895
  */
684
896
 
685
- function makeFoldWeightedDecompose_1(z, costFn, max, decompose, f) {
897
+ function makeFoldWeightedDecompose_1(z, costFn, max, decompose, f, __tsplusTrace) {
686
898
  return defer_1(() => {
687
899
  /**
688
900
  * @tsplus tailRec
@@ -725,35 +937,46 @@ function makeFoldWeightedDecompose_1(z, costFn, max, decompose, f) {
725
937
  }
726
938
 
727
939
  return new tsplus_module_3.Sink(go(z(), 0, false, max()));
728
- });
940
+ }, __tsplusTrace);
729
941
  }
730
942
  /**
943
+ * Creates a sink that effectfully folds elements of type `In` into a
944
+ * structure of type `S`, until `max` worth of elements (determined by the
945
+ * `costFn`) have been folded.
946
+ *
947
+ * The `decompose` function will be used for decomposing elements that cause
948
+ * an `S` aggregate to cross `max` into smaller elements. Be vigilant with
949
+ * this function, it has to generate "simpler" values or the fold may never
950
+ * end. A value is considered indivisible if `decompose` yields the empty
951
+ * chunk or a single-valued chunk. In these cases, there is no other choice
952
+ * than to yield a value that will cross the threshold.
953
+ *
731
954
  * @tsplus static fncts.io.SinkOps foldWeightedDecomposeIO
732
955
  */
733
956
 
734
957
 
735
- function makeFoldWeightedDecomposeIO_1(z, costFn, max, decompose, f) {
958
+ function makeFoldWeightedDecomposeIO_1(z, costFn, max, decompose, f, __tsplusTrace) {
736
959
  return defer_1(() => {
737
960
  function fold(inp, s, max, dirty, cost, idx) {
738
961
  if (idx === inp.length) {
739
- return tsplus_module_9.succeedNow([s, cost, dirty, tsplus_module_1.empty()], fileName_1 + ":961:29");
962
+ return tsplus_module_9.succeedNow([s, cost, dirty, tsplus_module_1.empty()], __tsplusTrace);
740
963
  } else {
741
964
  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 => {
965
+ return tsplus_module_9.flatMap_(tsplus_module_9.map_(costFn(s, elem), _ => cost + _, __tsplusTrace), total => {
743
966
  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");
967
+ return tsplus_module_9.flatMap_(f(s, elem), s => fold(inp, s, max, true, total, idx + 1), __tsplusTrace);
745
968
  } else {
746
969
  return tsplus_module_9.flatMap_(decompose(elem), decomposed => {
747
970
  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");
971
+ return tsplus_module_9.map_(f(s, elem), s => [s, total, true, tsplus_module_2.drop_(inp, idx + 1)], __tsplusTrace);
749
972
  } 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");
973
+ return tsplus_module_9.succeedNow([s, cost, dirty, tsplus_module_2.drop_(inp, idx)], __tsplusTrace);
751
974
  } else {
752
975
  return fold(tsplus_module_2.concat_(decomposed, tsplus_module_2.drop_(inp, idx + 1)), s, max, dirty, cost, 0);
753
976
  }
754
- }, fileName_1 + ":970:45");
977
+ }, __tsplusTrace);
755
978
  }
756
- }, fileName_1 + ":966:19");
979
+ }, __tsplusTrace);
757
980
  }
758
981
  }
759
982
 
@@ -770,22 +993,40 @@ function makeFoldWeightedDecomposeIO_1(z, costFn, max, decompose, f) {
770
993
  }
771
994
 
772
995
  return new tsplus_module_3.Sink(go(z(), 0, false, max()));
773
- });
996
+ }, __tsplusTrace);
774
997
  }
775
998
  /**
999
+ * Creates a sink that folds elements of type `In` into a structure of type
1000
+ * `S`, until `max` worth of elements (determined by the `costFn`) have been
1001
+ * folded.
1002
+ *
1003
+ * @note
1004
+ * Elements that have an individual cost larger than `max` will force the
1005
+ * sink to cross the `max` cost. See {@link makeFoldWeightedDecompose} for a variant
1006
+ * that can handle these cases.
1007
+ *
776
1008
  * @tsplus static fncts.io.SinkOps foldWeighted
777
1009
  */
778
1010
 
779
1011
 
780
- export function makeFoldWeighted(z, costFn, max, f) {
781
- return makeFoldWeightedDecompose_1(z, costFn, max, tsplus_module_22.single, f);
1012
+ export function makeFoldWeighted(z, costFn, max, f, __tsplusTrace) {
1013
+ return makeFoldWeightedDecompose_1(z, costFn, max, tsplus_module_24.single, f, __tsplusTrace);
782
1014
  }
783
1015
  /**
1016
+ * Creates a sink that effectfully folds elements of type `In` into a
1017
+ * structure of type `S`, until `max` worth of elements (determined by the
1018
+ * `costFn`) have been folded.
1019
+ *
1020
+ * @note
1021
+ * Elements that have an individual cost larger than `max` will force the
1022
+ * sink to cross the `max` cost. See {@link makeFoldWeightedDecomposeIO} for a
1023
+ * variant that can handle these cases.
1024
+ *
784
1025
  * @tsplus static fncts.io.SinkOps foldWeightedIO
785
1026
  */
786
1027
 
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);
1028
+ export function makeFoldWeightedIO(z, costFn, max, f, __tsplusTrace) {
1029
+ return makeFoldWeightedDecomposeIO_1(z, costFn, max, inp => tsplus_module_9.succeedNow(tsplus_module_24.single(inp), __tsplusTrace), f, __tsplusTrace);
789
1030
  }
790
1031
  /**
791
1032
  * Transforms this sink's result.
@@ -836,14 +1077,19 @@ function matchSink_1(self, onFailure, onSuccess, __tsplusTrace) {
836
1077
  })));
837
1078
  }
838
1079
  /**
1080
+ * Switch to another sink in case of failure
1081
+ *
839
1082
  * @tsplus fluent fncts.io.Sink orElse
840
1083
  */
841
1084
 
842
1085
 
843
1086
  export function orElse(self, that, __tsplusTrace) {
844
- return defer_1(() => new tsplus_module_3.Sink(tsplus_module_4.orElse_(self.channel, that().channel)));
1087
+ return defer_1(() => new tsplus_module_3.Sink(tsplus_module_4.orElse_(self.channel, that().channel)), __tsplusTrace);
845
1088
  }
846
1089
  /**
1090
+ * Provides the sink with its required environment, which eliminates its
1091
+ * dependency on `R`.
1092
+ *
847
1093
  * @tsplus fluent fncts.io.Sink provideEnvironment
848
1094
  */
849
1095
 
@@ -851,20 +1097,29 @@ export function provideEnvironment(self, r, __tsplusTrace) {
851
1097
  return new tsplus_module_3.Sink(tsplus_module_4.provideEnvironment_(self.channel, r));
852
1098
  }
853
1099
  /**
1100
+ * Runs both sinks in parallel on the input, returning the result or the
1101
+ * error from the one that finishes first.
1102
+ *
854
1103
  * @tsplus fluent fncts.io.Sink race
855
1104
  */
856
1105
 
857
- export function race(self, that) {
858
- return map_1(raceBoth_1(self, that), result => tsplus_module_23.merge(result), fileName_1 + ":1136:33");
1106
+ export function race(self, that, __tsplusTrace) {
1107
+ return map_1(raceBoth_1(self, that), result => tsplus_module_25.merge(result), __tsplusTrace);
859
1108
  }
860
1109
  /**
1110
+ * Runs both sinks in parallel on the input, returning the result or the error
1111
+ * from the one that finishes first.
1112
+ *
861
1113
  * @tsplus fluent fncts.io.Sink raceBoth
862
1114
  */
863
1115
 
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");
1116
+ function raceBoth_1(self, that, capacity = () => 16, __tsplusTrace) {
1117
+ 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);
866
1118
  }
867
1119
  /**
1120
+ * Runs both sinks in parallel on the input, using the specified merge
1121
+ * function as soon as one result or the other has been computed.
1122
+ *
868
1123
  * @tsplus fluent fncts.io.Sink raceWith
869
1124
  */
870
1125
 
@@ -873,16 +1128,18 @@ function raceWith_1(self, that, leftDone, rightDone, capacity = () => 16, __tspl
873
1128
  const scoped = tsplus_module_9.defer(() => {
874
1129
  const that0 = that();
875
1130
  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 => {
1131
+ 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 => {
877
1132
  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)));
1133
+ const writer = tsplus_module_28.mergeWith_(tsplus_module_4.pipeTo_(c1, self.channel), tsplus_module_4.pipeTo_(c2, that0.channel), leftDone, rightDone);
1134
+ 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)));
880
1135
  return new tsplus_module_3.Sink(channel);
881
1136
  }, __tsplusTrace), __tsplusTrace), __tsplusTrace);
882
1137
  }, __tsplusTrace);
883
- return unwrapScoped_1(() => scoped);
1138
+ return unwrapScoped_1(() => scoped, __tsplusTrace);
884
1139
  }
885
1140
  /**
1141
+ * Accesses the specified service in the environment of the effect.
1142
+ *
886
1143
  * @tsplus static fncts.io.SinkOps service
887
1144
  */
888
1145
 
@@ -891,18 +1148,23 @@ export function service(
891
1148
  /** @tsplus auto */
892
1149
  tag) {
893
1150
  const tag_1 = tag;
894
- return serviceWith_1(tsplus_module_12.identity, tag_1);
1151
+ return serviceWith_1(tsplus_module_14.identity, tag_1);
895
1152
  }
896
1153
  /**
1154
+ * Accesses the specified service in the environment of the sink.
1155
+ *
897
1156
  * @tsplus static fncts.io.SinkOps serviceWith
898
1157
  */
899
1158
 
900
1159
  function serviceWith_1(f,
901
1160
  /** @tsplus auto */
902
1161
  tag) {
903
- return fromIO_1(() => tsplus_module_11.serviceWith(f, tag));
1162
+ return fromIO_1(() => tsplus_module_13.serviceWith(f, tag), fileName_1 + ":1526:21");
904
1163
  }
905
1164
  /**
1165
+ * Accesses the specified service in the environment of the sink in the
1166
+ * context of an effect.
1167
+ *
906
1168
  * @tsplus static fncts.io.SinkOps serviceWithIO
907
1169
  */
908
1170
 
@@ -910,22 +1172,29 @@ tag) {
910
1172
  export function serviceWithIO(f,
911
1173
  /** @tsplus auto */
912
1174
  tag) {
913
- return fromIO_1(() => tsplus_module_11.serviceWithIO(f, tag, fileName_1 + ":1210:38"));
1175
+ return fromIO_1(() => tsplus_module_13.serviceWithIO(f, tag, fileName_1 + ":1539:38"), fileName_1 + ":1539:21");
914
1176
  }
915
1177
  /**
1178
+ * Accesses the specified service in the environment of the sink in the
1179
+ * context of a sink.
1180
+ *
916
1181
  * @tsplus static fncts.io.SinkOps serviceWithSink
917
1182
  */
918
1183
 
919
1184
  export function serviceWithSink(f,
920
1185
  /** @tsplus auto */
921
1186
  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)));
1187
+ return new tsplus_module_3.Sink(tsplus_module_4.unwrap(() => tsplus_module_13.serviceWith(tsplus_module_14.compose_(f, s => s.channel), tag)));
923
1188
  }
924
1189
  /**
1190
+ * Splits the sink on the specified predicate, returning a new sink that
1191
+ * consumes elements until an element after the first satisfies the specified
1192
+ * predicate.
1193
+ *
925
1194
  * @tsplus fluent fncts.io.Sink splitWhere
926
1195
  */
927
1196
 
928
- export function splitWhere(self, p) {
1197
+ export function splitWhere(self, p, __tsplusTrace) {
929
1198
  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
1199
  }
931
1200
 
@@ -934,7 +1203,7 @@ function splitter(p, written, leftovers) {
934
1203
  if (tsplus_module_2.isEmpty(inp)) {
935
1204
  return splitter(p, written, leftovers);
936
1205
  } else if (written) {
937
- const index = tsplus_module_28.findIndex(inp, p);
1206
+ const index = tsplus_module_30.findIndex(inp, p);
938
1207
 
939
1208
  if (index === -1) {
940
1209
  return tsplus_module_5.apSecond_(tsplus_module_4.writeNow(inp), splitter(p, true, leftovers));
@@ -943,7 +1212,7 @@ function splitter(p, written, leftovers) {
943
1212
  return tsplus_module_5.apSecond_(tsplus_module_4.writeNow(left), tsplus_module_4.fromIO(() => tsplus_module_6.set_(leftovers, right)));
944
1213
  }
945
1214
  } else {
946
- const index = tsplus_module_28.findIndex(inp, p);
1215
+ const index = tsplus_module_30.findIndex(inp, p);
947
1216
 
948
1217
  if (index === -1) {
949
1218
  return tsplus_module_5.apSecond_(tsplus_module_4.writeNow(inp), splitter(p, true, leftovers));
@@ -955,6 +1224,8 @@ function splitter(p, written, leftovers) {
955
1224
  }, tsplus_module_5.failCauseNow, tsplus_module_5.succeedNow);
956
1225
  }
957
1226
  /**
1227
+ * A sink that immediately ends with the specified value.
1228
+ *
958
1229
  * @tsplus static fncts.io.SinkOps succeed
959
1230
  */
960
1231
 
@@ -963,6 +1234,8 @@ export function succeed(z, __tsplusTrace) {
963
1234
  return new tsplus_module_3.Sink(tsplus_module_5.succeed(z));
964
1235
  }
965
1236
  /**
1237
+ * A sink that immediately ends with the specified value.
1238
+ *
966
1239
  * @tsplus static fncts.io.SinkOps succeedNow
967
1240
  */
968
1241
 
@@ -970,6 +1243,9 @@ export function succeedNow(z, __tsplusTrace) {
970
1243
  return new tsplus_module_3.Sink(tsplus_module_5.succeedNow(z));
971
1244
  }
972
1245
  /**
1246
+ * Summarize a sink by running an effect when the sink starts and again when
1247
+ * it completes
1248
+ *
973
1249
  * @tsplus fluent fncts.io.Sink summarized
974
1250
  */
975
1251
 
@@ -982,14 +1258,16 @@ function summarized_1(self, summary, f, __tsplusTrace) {
982
1258
 
983
1259
 
984
1260
  export function timed(self, __tsplusTrace) {
985
- return summarized_1(self, () => tsplus_module_29.currentTime, (start, end) => tsplus_module_30.fromInterval(start, end), __tsplusTrace);
1261
+ return summarized_1(self, () => tsplus_module_31.currentTime, (start, end) => tsplus_module_32.fromInterval(start, end), __tsplusTrace);
986
1262
  }
987
1263
  /**
1264
+ * Creates a sink produced from an effect.
1265
+ *
988
1266
  * @tsplus static fncts.io.SinkOps unwrap
989
1267
  */
990
1268
 
991
1269
  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")));
1270
+ return new tsplus_module_3.Sink(tsplus_module_4.unwrap(() => tsplus_module_9.map_(io(), sink => sink.channel, fileName_1 + ":1678:42")));
993
1271
  }
994
1272
  /**
995
1273
  * Creates a sink produced from a scoped effect.
@@ -998,23 +1276,30 @@ function unwrap_1(io) {
998
1276
  */
999
1277
 
1000
1278
 
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")));
1279
+ function unwrapScoped_1(scoped, __tsplusTrace) {
1280
+ return new tsplus_module_3.Sink(tsplus_module_4.unwrapScoped(() => tsplus_module_9.map_(scoped(), sink => sink.channel, __tsplusTrace)));
1003
1281
  }
1004
1282
  /**
1283
+ * Feeds inputs to this sink until it yields a result, then switches over to
1284
+ * the provided sink until it yields a result, finally combining the two
1285
+ * results into a tuple.
1286
+ *
1005
1287
  * @tsplus fluent fncts.io.Sink zip
1006
1288
  */
1007
1289
 
1008
1290
 
1009
- export function zip(self, that) {
1010
- return zipWith_1(() => self, that, tsplus_module_12.tuple);
1291
+ export function zip(self, that, __tsplusTrace) {
1292
+ return zipWith_1(() => self, that, tsplus_module_14.tuple, __tsplusTrace);
1011
1293
  }
1012
1294
  /**
1295
+ * Runs both sinks in parallel on the input and combines the results in a
1296
+ * tuple.
1297
+ *
1013
1298
  * @tsplus fluent fncts.io.Sink zipC
1014
1299
  */
1015
1300
 
1016
- export function zipC(self, that) {
1017
- return zipWithC_1(() => self, that, tsplus_module_12.tuple);
1301
+ export function zipC(self, that, __tsplusTrace) {
1302
+ return zipWithC_1(() => self, that, tsplus_module_14.tuple, __tsplusTrace);
1018
1303
  }
1019
1304
  /**
1020
1305
  * Feeds inputs to this sink until it yields a result, then switches over to
@@ -1024,8 +1309,8 @@ export function zipC(self, that) {
1024
1309
  * @tsplus fluent fncts.io.Sink zipWith
1025
1310
  */
1026
1311
 
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"));
1312
+ function zipWith_1(self, that, f, __tsplusTrace) {
1313
+ return defer_1(() => flatMap_1(self(), z => map_1(that(), z1 => f(z, z1), __tsplusTrace), __tsplusTrace), __tsplusTrace);
1029
1314
  }
1030
1315
  /**
1031
1316
  * Runs both sinks in parallel on the input and combines the results using the
@@ -1035,7 +1320,7 @@ function zipWith_1(self, that, f) {
1035
1320
  */
1036
1321
 
1037
1322
 
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"))))));
1323
+ function zipWithC_1(self, that, f, __tsplusTrace) {
1324
+ 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);
1040
1325
  }
1041
1326
  //# sourceMappingURL=api.mjs.map