@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/_src/Sink/api.ts CHANGED
@@ -3,6 +3,8 @@ import { AtomicReference } from "@fncts/base/internal/AtomicReference";
3
3
  import { MergeDecision } from "../Channel/internal/MergeDecision.js";
4
4
 
5
5
  /**
6
+ * Like {@link zip}, but keeps only the result from this sink
7
+ *
6
8
  * @tsplus fluent fncts.io.Sink apFirst
7
9
  */
8
10
  export function apFirst<R, E, In, L, Z, R1, E1, In1 extends In, L1 extends L, Z1>(
@@ -13,6 +15,8 @@ export function apFirst<R, E, In, L, Z, R1, E1, In1 extends In, L1 extends L, Z1
13
15
  }
14
16
 
15
17
  /**
18
+ * Like {@link zipC}, but keeps only the result from this sink
19
+ *
16
20
  * @tsplus fluent fncts.io.Sink apFirstC
17
21
  */
18
22
  export function apFirstC<R, E, In, L, Z, R1, E1, In1 extends In, L1 extends L, Z1>(
@@ -23,33 +27,47 @@ export function apFirstC<R, E, In, L, Z, R1, E1, In1 extends In, L1 extends L, Z
23
27
  }
24
28
 
25
29
  /**
30
+ * Like {@link zip}, but keeps only the result from the `that` sink
31
+ *
26
32
  * @tsplus fluent fncts.io.Sink apSecond
27
33
  */
28
34
  export function apSecond<R, E, In, L, Z, R1, E1, In1 extends In, L1 extends L, Z1>(
29
35
  self: Sink<R, E, In, L, Z>,
30
36
  that: Lazy<Sink<R1, E1, In1, L1, Z1>>,
37
+ __tsplusTrace?: string,
31
38
  ): Sink<R & R1, E | E1, In & In1, L | L1, Z1> {
32
39
  return self.zipWith(that, (_, z1) => z1);
33
40
  }
34
41
 
35
42
  /**
43
+ * Like {@link zipC}, but keeps only the result from the `that` sink
44
+ *
36
45
  * @tsplus fluent fncts.io.Sink apSecondC
37
46
  */
38
47
  export function apSecondC<R, E, In, L, Z, R1, E1, In1 extends In, L1 extends L, Z1>(
39
48
  self: Sink<R, E, In, L, Z>,
40
49
  that: Lazy<Sink<R1, E1, In1, L1, Z1>>,
50
+ __tsplusTrace?: string,
41
51
  ): Sink<R & R1, E | E1, In & In1, L | L1, Z1> {
42
52
  return self.zipWithC(that, (_, z1) => z1);
43
53
  }
44
54
 
45
55
  /**
56
+ * Replaces this sink's result with the provided value.
57
+ *
46
58
  * @tsplus fluent fncts.io.Sink as
47
59
  */
48
- export function as<R, E, In, L, Z, Z1>(self: Sink<R, E, In, L, Z>, z: Lazy<Z1>): Sink<R, E, In, L, Z1> {
60
+ export function as<R, E, In, L, Z, Z1>(
61
+ self: Sink<R, E, In, L, Z>,
62
+ z: Lazy<Z1>,
63
+ __tsplusTrace?: string,
64
+ ): Sink<R, E, In, L, Z1> {
49
65
  return self.map(() => z());
50
66
  }
51
67
 
52
68
  /**
69
+ * Repeatedly runs the sink and accumulates its results into a chunk
70
+ *
53
71
  * @tsplus fluent fncts.io.Sink collectAll
54
72
  */
55
73
  export function collectAll<R, E, In extends L, L, Z>(
@@ -64,6 +82,10 @@ export function collectAll<R, E, In extends L, L, Z>(
64
82
  }
65
83
 
66
84
  /**
85
+ * Repeatedly runs the sink for as long as its results satisfy the predicate
86
+ * `p`. The sink's results will be accumulated using the stepping function
87
+ * `f`.
88
+ *
67
89
  * @tsplus fluent fncts.io.Sink collectAllWhileWith
68
90
  */
69
91
  export function collectAllWhileWith<R, E, In extends L, L, Z, S>(
@@ -104,6 +126,9 @@ export function collectAllWhileWith<R, E, In extends L, L, Z, S>(
104
126
  }
105
127
 
106
128
  /**
129
+ * Collects the leftovers from the stream when the sink succeeds and returns
130
+ * them as part of the sink's result
131
+ *
107
132
  * @tsplus getter fncts.io.Sink collectLeftover
108
133
  */
109
134
  export function collectLeftover<R, E, In, L, Z>(
@@ -114,18 +139,27 @@ export function collectLeftover<R, E, In, L, Z>(
114
139
  }
115
140
 
116
141
  /**
142
+ * Transforms this sink's input elements.
143
+ *
117
144
  * @tsplus fluent fncts.io.Sink contramap
118
145
  */
119
- export function contramap<R, E, In, L, Z, In1>(self: Sink<R, E, In, L, Z>, f: (inp: In1) => In): Sink<R, E, In1, L, Z> {
146
+ export function contramap<R, E, In, L, Z, In1>(
147
+ self: Sink<R, E, In, L, Z>,
148
+ f: (inp: In1) => In,
149
+ __tsplusTrace?: string,
150
+ ): Sink<R, E, In1, L, Z> {
120
151
  return self.contramapChunks((chunk) => chunk.map(f));
121
152
  }
122
153
 
123
154
  /**
155
+ * Transforms this sink's input chunks. `f` must preserve chunking-invariance
156
+ *
124
157
  * @tsplus fluent fncts.io.Sink contramapChunks
125
158
  */
126
159
  export function contramapChunks<R, E, In, L, Z, In1>(
127
160
  self: Sink<R, E, In, L, Z>,
128
161
  f: (chunk: Conc<In1>) => Conc<In>,
162
+ __tsplusTrace?: string,
129
163
  ): Sink<R, E, In1, L, Z> {
130
164
  const loop: Channel<R, never, Conc<In1>, unknown, never, Conc<In>, unknown> = Channel.readWith(
131
165
  (chunk) => Channel.writeNow(f(chunk)) > loop,
@@ -136,11 +170,15 @@ export function contramapChunks<R, E, In, L, Z, In1>(
136
170
  }
137
171
 
138
172
  /**
173
+ * Effectfully transforms this sink's input chunks. `f` must preserve
174
+ * chunking-invariance
175
+ *
139
176
  * @tsplus fluent fncts.io.Sink contramapChunksIO
140
177
  */
141
178
  export function contramapChunksIO<R, E, In, L, Z, R1, E1, In1>(
142
179
  self: Sink<R, E, In, L, Z>,
143
180
  f: (chunk: Conc<In1>) => IO<R1, E1, Conc<In>>,
181
+ __tsplusTrace?: string,
144
182
  ): Sink<R & R1, E | E1, In1, L, Z> {
145
183
  const loop: Channel<R & R1, never, Conc<In1>, unknown, E | E1, Conc<In>, unknown> = Channel.readWith(
146
184
  (chunk) => Channel.fromIO(f(chunk)).flatMap(Channel.writeNow) > loop,
@@ -151,63 +189,85 @@ export function contramapChunksIO<R, E, In, L, Z, R1, E1, In1>(
151
189
  }
152
190
 
153
191
  /**
192
+ * Effectfully transforms this sink's input elements.
193
+ *
154
194
  * @tsplus fluent fncts.io.Sink contramapIO
155
195
  */
156
196
  export function contramapIO<R, E, In, L, Z, R1, E1, In1>(
157
197
  self: Sink<R, E, In, L, Z>,
158
198
  f: (inp: In1) => IO<R1, E1, In>,
199
+ __tsplusTrace?: string,
159
200
  ): Sink<R & R1, E | E1, In1, L, Z> {
160
201
  return self.contramapChunksIO((chunk) => chunk.mapIO(f));
161
202
  }
162
203
 
163
204
  /**
205
+ * Transforms both inputs and result of this sink using the provided
206
+ * functions.
207
+ *
164
208
  * @tsplus fluent fncts.io.Sink dimap
165
209
  */
166
210
  export function dimap<R, E, In, L, Z, In1, Z1>(
167
211
  self: Sink<R, E, In, L, Z>,
168
212
  f: (inp: In1) => In,
169
213
  g: (z: Z) => Z1,
214
+ __tsplusTrace?: string,
170
215
  ): Sink<R, E, In1, L, Z1> {
171
216
  return self.contramap(f).map(g);
172
217
  }
173
218
 
174
219
  /**
220
+ * Transforms both input chunks and result of this sink using the provided
221
+ * functions.
222
+ *
175
223
  * @tsplus fluent fncts.io.Sink dimapChunks
176
224
  */
177
225
  export function dimapChunks<R, E, In, L, Z, In1, Z1>(
178
226
  self: Sink<R, E, In, L, Z>,
179
227
  f: (chunk: Conc<In1>) => Conc<In>,
180
228
  g: (z: Z) => Z1,
229
+ __tsplusTrace?: string,
181
230
  ): Sink<R, E, In1, L, Z1> {
182
231
  return self.contramapChunks(f).map(g);
183
232
  }
184
233
 
185
234
  /**
235
+ * Effectfully transforms both input chunks and result of this sink using the
236
+ * provided functions. `f` and `g` must preserve chunking-invariance
237
+ *
186
238
  * @tsplus fluent fncts.io.Sink dimapChunksIO
187
239
  */
188
240
  export function dimapChunksIO<R, E, In, L, Z, R1, E1, In1, R2, E2, Z1>(
189
241
  self: Sink<R, E, In, L, Z>,
190
242
  f: (chunk: Conc<In1>) => IO<R1, E1, Conc<In>>,
191
243
  g: (z: Z) => IO<R2, E2, Z1>,
244
+ __tsplusTrace?: string,
192
245
  ): Sink<R & R1 & R2, E | E1 | E2, In1, L, Z1> {
193
246
  return self.contramapChunksIO(f).mapIO(g);
194
247
  }
195
248
 
196
249
  /**
250
+ * Effectfully transforms both inputs and result of this sink using the
251
+ * provided functions.
252
+ *
197
253
  * @tsplus fluent fncts.io.Sink dimapIO
198
254
  */
199
255
  export function dimapIO<R, E, In, L, Z, R1, E1, In1, R2, E2, Z1>(
200
256
  self: Sink<R, E, In, L, Z>,
201
257
  f: (inp: In1) => IO<R1, E1, In>,
202
258
  g: (z: Z) => IO<R2, E2, Z1>,
259
+ __tsplusTrace?: string,
203
260
  ): Sink<R & R1 & R2, E | E1 | E2, In1, L, Z1> {
204
261
  return self.contramapIO(f).mapIO(g);
205
262
  }
206
263
 
207
264
  /**
265
+ * Returns a lazily constructed sink that may require effects for its
266
+ * creation.
267
+ *
208
268
  * @tsplus static fncts.io.SinkOps defer
209
269
  */
210
- export function defer<R, E, In, L, Z>(sink: Lazy<Sink<R, E, In, L, Z>>): Sink<R, E, In, L, Z> {
270
+ export function defer<R, E, In, L, Z>(sink: Lazy<Sink<R, E, In, L, Z>>, __tsplusTrace?: string): Sink<R, E, In, L, Z> {
211
271
  return new Sink(Channel.defer(sink().channel));
212
272
  }
213
273
 
@@ -225,9 +285,58 @@ const drainLoop: Channel<unknown, never, Conc<unknown>, unknown, never, Conc<nev
225
285
  export const drain: Sink<unknown, never, unknown, never, void> = new Sink(drainLoop);
226
286
 
227
287
  /**
288
+ * Drops incoming elements until the predicate `p` is satisfied.
289
+ *
290
+ * @tsplus static fncts.io.SinkOps dropUntil
291
+ */
292
+ export function makeDropUntil<In>(p: Predicate<In>, __tsplusTrace?: string): Sink<unknown, never, In, In, void> {
293
+ const loop: Channel<unknown, never, Conc<In>, any, never, Conc<In>, void> = Channel.readWith(
294
+ (inp: Conc<In>) => {
295
+ const leftover = inp.dropUntil(p);
296
+ const more = leftover.isEmpty;
297
+ if (more) {
298
+ return loop;
299
+ } else {
300
+ return Channel.writeNow(leftover) > Channel.id<never, Conc<In>, void>();
301
+ }
302
+ },
303
+ Channel.failNow,
304
+ () => Channel.unit,
305
+ );
306
+ return new Sink(loop);
307
+ }
308
+
309
+ /**
310
+ * Drops incoming elements until the effectful predicate `p` is satisfied.
311
+ *
312
+ * @tsplus static fncts.io.SinkOps dropUntilIO
313
+ */
314
+ export function makeDropUntilIO<R, E, In>(
315
+ p: (inp: In) => IO<R, E, boolean>,
316
+ __tsplusTrace?: string,
317
+ ): Sink<R, E, In, In, void> {
318
+ const loop: Channel<R, E, Conc<In>, any, E, Conc<In>, void> = Channel.readWith(
319
+ (inp: Conc<In>) =>
320
+ Channel.unwrap(
321
+ inp
322
+ .dropUntilIO(p)
323
+ .map((leftover) => (leftover.isEmpty ? loop : Channel.writeNow(leftover) > Channel.id<E, Conc<In>, void>())),
324
+ ),
325
+ Channel.failNow,
326
+ () => Channel.unit,
327
+ );
328
+ return new Sink(loop);
329
+ }
330
+
331
+ /**
332
+ * Drops incoming elements as long as the predicate `p` is satisfied.
333
+ *
228
334
  * @tsplus static fncts.io.SinkOps dropWhile
229
335
  */
230
- export function dropWhile<Err, In>(predicate: Predicate<In>): Sink<unknown, never, In, In, any> {
336
+ export function makeDropWhile<Err, In>(
337
+ predicate: Predicate<In>,
338
+ __tsplusTrace?: string,
339
+ ): Sink<unknown, never, In, In, any> {
231
340
  const loop: Channel<unknown, never, Conc<In>, any, never, Conc<In>, any> = Channel.readWith(
232
341
  (inp: Conc<In>) => {
233
342
  const leftover = inp.dropWhile(predicate);
@@ -245,6 +354,31 @@ export function dropWhile<Err, In>(predicate: Predicate<In>): Sink<unknown, neve
245
354
  }
246
355
 
247
356
  /**
357
+ * Drops incoming elements as long as the effectful predicate `p` is
358
+ * satisfied.
359
+ *
360
+ * @tsplus static fncts.io.SinkOps dropWhileIO
361
+ */
362
+ export function dropWhileIO<R, E, In>(
363
+ p: (inp: In) => IO<R, E, boolean>,
364
+ __tsplusTrace?: string,
365
+ ): Sink<R, E, In, In, void> {
366
+ const loop: Channel<R, E, Conc<In>, any, E, Conc<In>, void> = Channel.readWith(
367
+ (inp: Conc<In>) =>
368
+ Channel.unwrap(
369
+ inp
370
+ .dropWhileIO(p)
371
+ .map((leftover) => (leftover.isEmpty ? loop : Channel.writeNow(leftover) > Channel.id<E, Conc<In>, void>())),
372
+ ),
373
+ Channel.failNow,
374
+ () => Channel.unit,
375
+ );
376
+ return new Sink(loop);
377
+ }
378
+
379
+ /**
380
+ * Accesses the whole environment of the sink.
381
+ *
248
382
  * @tsplus static fncts.io.SinkOps environment
249
383
  */
250
384
  export function environment<R>(__tsplusTrace?: string): Sink<R, never, unknown, never, Environment<R>> {
@@ -252,6 +386,8 @@ export function environment<R>(__tsplusTrace?: string): Sink<R, never, unknown,
252
386
  }
253
387
 
254
388
  /**
389
+ * Accesses the environment of the sink.
390
+ *
255
391
  * @tsplus static fncts.io.SinkOps environmentWith
256
392
  */
257
393
  export function environmentWith<R, Z>(
@@ -262,6 +398,8 @@ export function environmentWith<R, Z>(
262
398
  }
263
399
 
264
400
  /**
401
+ * Accesses the environment of the sink in the context of an effect.
402
+ *
265
403
  * @tsplus static fncts.io.SinkOps environmentWithIO
266
404
  */
267
405
  export function environmentWithIO<R, R1, E, Z>(
@@ -272,6 +410,8 @@ export function environmentWithIO<R, R1, E, Z>(
272
410
  }
273
411
 
274
412
  /**
413
+ * Accesses the environment of the sink in the context of a sink.
414
+ *
275
415
  * @tsplus static fncts.io.SinkOps environmentWithSink
276
416
  */
277
417
  export function environmentWithSink<R, R1, E, In, L, Z>(
@@ -282,13 +422,17 @@ export function environmentWithSink<R, R1, E, In, L, Z>(
282
422
  }
283
423
 
284
424
  /**
425
+ * A sink that always fails with the specified error.
426
+ *
285
427
  * @tsplus static fncts.io.SinkOps fail
286
428
  */
287
- export function fail<E>(e: Lazy<E>): Sink<unknown, E, unknown, never, never> {
429
+ export function fail<E>(e: Lazy<E>, __tsplusTrace?: string): Sink<unknown, E, unknown, never, never> {
288
430
  return new Sink(Channel.fail(e));
289
431
  }
290
432
 
291
433
  /**
434
+ * Creates a sink halting with a specified cause.
435
+ *
292
436
  * @tsplus static fncts.io.SinkOps failCause
293
437
  */
294
438
  export function failCause<E>(cause: Lazy<Cause<E>>, __tsplusTrace?: string): Sink<unknown, E, unknown, never, never> {
@@ -296,6 +440,8 @@ export function failCause<E>(cause: Lazy<Cause<E>>, __tsplusTrace?: string): Sin
296
440
  }
297
441
 
298
442
  /**
443
+ * Creates a sink halting with a specified cause.
444
+ *
299
445
  * @tsplus static fncts.io.SinkOps failCauseNow
300
446
  */
301
447
  export function failCauseNow<E>(cause: Cause<E>, __tsplusTrace?: string): Sink<unknown, E, unknown, never, never> {
@@ -303,6 +449,8 @@ export function failCauseNow<E>(cause: Cause<E>, __tsplusTrace?: string): Sink<u
303
449
  }
304
450
 
305
451
  /**
452
+ * A sink that always fails with the specified error.
453
+ *
306
454
  * @tsplus static fncts.io.SinkOps failNow
307
455
  */
308
456
  export function failNow<E>(e: E, __tsplusTrace?: string): Sink<unknown, E, unknown, never, never> {
@@ -310,6 +458,8 @@ export function failNow<E>(e: E, __tsplusTrace?: string): Sink<unknown, E, unkno
310
458
  }
311
459
 
312
460
  /**
461
+ * Filters the sink's input with the given predicate
462
+ *
313
463
  * @tsplus static fncts.io.SinkOps filterInput
314
464
  */
315
465
  export function filterInput<R, E, In, L, Z>(
@@ -321,6 +471,8 @@ export function filterInput<R, E, In, L, Z>(
321
471
  }
322
472
 
323
473
  /**
474
+ * Filters the sink's input with the given IO predicate
475
+ *
324
476
  * @tsplus static fncts.io.SinkOps filterInputIO
325
477
  */
326
478
  export function filterInputIO<R, E, In, L, Z, R1, E1>(
@@ -332,6 +484,8 @@ export function filterInputIO<R, E, In, L, Z, R1, E1>(
332
484
  }
333
485
 
334
486
  /**
487
+ * Creates a sink that produces values until one verifies the predicate `f`.
488
+ *
335
489
  * @tsplus fluent fncts.io.Sink findIO
336
490
  */
337
491
  export function findIO<R, E, In extends L, L, Z, R1, E1>(
@@ -373,6 +527,12 @@ export function findIO<R, E, In extends L, L, Z, R1, E1>(
373
527
  }
374
528
 
375
529
  /**
530
+ * Runs this sink until it yields a result, then uses that result to create
531
+ * another sink from the provided function which will continue to run until it
532
+ * yields a result.
533
+ *
534
+ * This function essentially runs sinks in sequence.
535
+ *
376
536
  * @tsplus fluent fncts.io.Sink flatMap
377
537
  */
378
538
  export function flatMap<R, E, In, L, Z, R1, E1, In1 extends In, L1, Z1>(
@@ -384,6 +544,8 @@ export function flatMap<R, E, In, L, Z, R1, E1, In1 extends In, L1, Z1>(
384
544
  }
385
545
 
386
546
  /**
547
+ * Creates a sink from a {@link Channel}
548
+ *
387
549
  * @tsplus static fncts.io.SinkOps fromChannel
388
550
  * @tsplus static fncts.io.SinkOps __call
389
551
  */
@@ -394,6 +556,8 @@ export function fromChannel<R, E, In, L, Z>(
394
556
  }
395
557
 
396
558
  /**
559
+ * Creates a sink from a chunk processing function.
560
+ *
397
561
  * @tsplus static fncts.io.SinkOps fromPush
398
562
  */
399
563
  export function fromPush<R, E, In, L, Z, R1>(
@@ -430,16 +594,27 @@ function fromPushPull<R, E, In, L, Z>(
430
594
  }
431
595
 
432
596
  /**
597
+ * Create a sink which enqueues each element into the specified queue.
598
+ *
433
599
  * @tsplus static fncts.io.SinkOps fromQueue
434
600
  */
435
- export function fromQueue<In>(queue: Lazy<Queue.Enqueue<In>>): Sink<unknown, never, In, never, void> {
601
+ export function fromQueue<In>(
602
+ queue: Lazy<Queue.Enqueue<In>>,
603
+ __tsplusTrace?: string,
604
+ ): Sink<unknown, never, In, never, void> {
436
605
  return Sink.unwrap(IO.succeed(queue).map((queue) => Sink.foreachChunk((inp) => queue.offerAll(inp))));
437
606
  }
438
607
 
439
608
  /**
609
+ * Create a sink which enqueues each element into the specified queue. The
610
+ * queue will be shutdown once the stream is closed.
611
+ *
440
612
  * @tsplus static fncts.io.SinkOps fromQueueWithShutdown
441
613
  */
442
- export function fromQueueWithShutdown<In>(queue: Lazy<Queue.Enqueue<In>>): Sink<unknown, never, In, never, void> {
614
+ export function fromQueueWithShutdown<In>(
615
+ queue: Lazy<Queue.Enqueue<In>>,
616
+ __tsplusTrace?: string,
617
+ ): Sink<unknown, never, In, never, void> {
443
618
  return Sink.unwrapScoped(
444
619
  IO.succeed(queue)
445
620
  .acquireRelease((queue) => queue.shutdown)
@@ -448,27 +623,39 @@ export function fromQueueWithShutdown<In>(queue: Lazy<Queue.Enqueue<In>>): Sink<
448
623
  }
449
624
 
450
625
  /**
626
+ * Create a sink which publishes each element to the specified hub.
627
+ *
451
628
  * @tsplus static fncts.io.SinkOps fromHub
452
629
  */
453
- export function fromHub<In>(hub: Lazy<Hub<In>>): Sink<unknown, never, In, never, void> {
630
+ export function fromHub<In>(hub: Lazy<Hub<In>>, __tsplusTrace?: string): Sink<unknown, never, In, never, void> {
454
631
  return Sink.fromQueue(hub);
455
632
  }
456
633
 
457
634
  /**
635
+ * Create a sink which publishes each element to the specified hub. The hub
636
+ * will be shutdown once the stream is closed.
637
+ *
458
638
  * @tsplus static fncts.io.SinkOps fromHubWithShutdown
459
639
  */
460
- export function fromHubWithShutdown<In>(hub: Lazy<Hub<In>>): Sink<unknown, never, In, never, void> {
640
+ export function fromHubWithShutdown<In>(
641
+ hub: Lazy<Hub<In>>,
642
+ __tsplusTrace?: string,
643
+ ): Sink<unknown, never, In, never, void> {
461
644
  return Sink.fromQueueWithShutdown(hub);
462
645
  }
463
646
 
464
647
  /**
648
+ * Creates a single-value sink produced from an effect
649
+ *
465
650
  * @tsplus static fncts.io.SinkOps fromIO
466
651
  */
467
- export function fromIO<R, E, Z>(b: Lazy<IO<R, E, Z>>): Sink<R, E, unknown, never, Z> {
652
+ export function fromIO<R, E, Z>(b: Lazy<IO<R, E, Z>>, __tsplusTrace?: string): Sink<R, E, unknown, never, Z> {
468
653
  return new Sink(Channel.fromIO(b));
469
654
  }
470
655
 
471
656
  /**
657
+ * Creates a sink halting with the specified unchecked value.
658
+ *
472
659
  * @tsplus static fncts.io.SinkOps halt
473
660
  */
474
661
  export function halt(defect: Lazy<unknown>, __tsplusTrace?: string): Sink<unknown, never, unknown, never, never> {
@@ -476,6 +663,8 @@ export function halt(defect: Lazy<unknown>, __tsplusTrace?: string): Sink<unknow
476
663
  }
477
664
 
478
665
  /**
666
+ * Creates a sink halting with the specified unchecked value.
667
+ *
479
668
  * @tsplus static fncts.io.SinkOps haltNow
480
669
  */
481
670
  export function haltNow(defect: unknown, __tsplusTrace?: string): Sink<unknown, never, unknown, never, never> {
@@ -483,6 +672,8 @@ export function haltNow(defect: unknown, __tsplusTrace?: string): Sink<unknown,
483
672
  }
484
673
 
485
674
  /**
675
+ * Creates a sink containing the first value.
676
+ *
486
677
  * @tsplus static fncts.io.SinkOps head
487
678
  */
488
679
  export function head<In>(__tsplusTrace?: string): Sink<unknown, never, In, In, Maybe<In>> {
@@ -498,6 +689,8 @@ export function head<In>(__tsplusTrace?: string): Sink<unknown, never, In, In, M
498
689
  }
499
690
 
500
691
  /**
692
+ * Drains the remaining elements from the stream after the sink finishes
693
+ *
501
694
  * @tsplus getter fncts.io.Sink ignoreLeftover
502
695
  */
503
696
  export function ignoreLeftover<R, E, In, L, Z>(
@@ -508,6 +701,8 @@ export function ignoreLeftover<R, E, In, L, Z>(
508
701
  }
509
702
 
510
703
  /**
704
+ * Creates a sink containing the last value.
705
+ *
511
706
  * @tsplus static fncts.io.SinkOps last
512
707
  */
513
708
  export function last<In>(__tsplusTrace?: string): Sink<unknown, never, In, In, Maybe<In>> {
@@ -515,6 +710,9 @@ export function last<In>(__tsplusTrace?: string): Sink<unknown, never, In, In, M
515
710
  }
516
711
 
517
712
  /**
713
+ * Creates a sink that does not consume any input but provides the given chunk
714
+ * as its leftovers
715
+ *
518
716
  * @tsplus static fncts.io.SinkOps leftover
519
717
  */
520
718
  export function leftover<L>(c: Lazy<Conc<L>>, __tsplusTrace?: string): Sink<unknown, never, unknown, L, void> {
@@ -522,6 +720,8 @@ export function leftover<L>(c: Lazy<Conc<L>>, __tsplusTrace?: string): Sink<unkn
522
720
  }
523
721
 
524
722
  /**
723
+ * Logs the specified message at the current log level.
724
+ *
525
725
  * @tsplus static fncts.io.SinkOps log
526
726
  */
527
727
  export function log(message: Lazy<string>, __tsplusTrace?: string): Sink<unknown, never, unknown, never, void> {
@@ -545,6 +745,12 @@ function collectLoop<A>(state: Conc<A>): Channel<unknown, never, Conc<A>, unknow
545
745
  );
546
746
  }
547
747
 
748
+ /**
749
+ * A sink that collects first `n` elements into a chunk. Note that the chunk
750
+ * is preallocated and must fit in memory.
751
+ *
752
+ * @tsplus static fncts.io.SinkOps collectAllN
753
+ */
548
754
  export function makeCollectAllN<In>(n: Lazy<number>): Sink<unknown, never, In, In, Conc<In>> {
549
755
  return Sink.fromIO(IO.succeed(new ConcBuilder<In>())).flatMap((builder) =>
550
756
  Sink.foldUntil<In, ConcBuilder<In>>(builder, n, (builder, inp) => builder.append(inp)).map((builder) =>
@@ -566,6 +772,9 @@ export function makeForeach<R, Err, In>(
566
772
  }
567
773
 
568
774
  /**
775
+ * A sink that executes the provided effectful function for every chunk fed to
776
+ * it.
777
+ *
569
778
  * @tsplus static fncts.io.SinkOps foreachChunk
570
779
  */
571
780
  export function makeForeachChunk<R, E, In>(
@@ -615,6 +824,9 @@ function foreachWhileLoop<R, Err, In>(
615
824
  }
616
825
 
617
826
  /**
827
+ * A sink that executes the provided effectful function for every chunk fed to
828
+ * it until `f` evaluates to `false`.
829
+ *
618
830
  * @tsplus static fncts.io.SinkOps foreachChunkWhile
619
831
  */
620
832
  export function makeForeachChunkWhile<R, E, In>(
@@ -631,6 +843,9 @@ export function makeForeachChunkWhile<R, E, In>(
631
843
  }
632
844
 
633
845
  /**
846
+ * A sink that folds its inputs with the provided function, termination
847
+ * predicate and initial state.
848
+ *
634
849
  * @tsplus static fncts.io.SinkOps fold
635
850
  */
636
851
  export function makeFold<In, S>(
@@ -689,6 +904,11 @@ function foldReader<S, In>(
689
904
  }
690
905
 
691
906
  /**
907
+ * Creates a sink that folds elements of type `In` into a structure of type
908
+ * `S` until `max` elements have been folded.
909
+ *
910
+ * Like {@link foldWeighted}, but with a constant cost function of 1.
911
+ *
692
912
  * @tsplus static fncts.io.SinkOps foldUntil
693
913
  */
694
914
  export function makeFoldUntil<In, S>(
@@ -709,12 +929,18 @@ export function makeFoldUntil<In, S>(
709
929
  }
710
930
 
711
931
  /**
932
+ * A sink that folds its input chunks with the provided function, termination
933
+ * predicate and initial state. `contFn` condition is checked only for the
934
+ * initial value and at the end of processing of each chunk. `f` and `contFn`
935
+ * must preserve chunking-invariance.
936
+ *
712
937
  * @tsplus static fncts.io.SinkOps foldChunks
713
938
  */
714
939
  export function makeFoldChunks<In, S>(
715
940
  z: Lazy<S>,
716
941
  contFn: Predicate<S>,
717
942
  f: (s: S, inp: Conc<In>) => S,
943
+ __tsplusTrace?: string,
718
944
  ): Sink<unknown, never, In, never, S> {
719
945
  return Sink.defer(new Sink(foldChunksReader(z(), contFn, f)));
720
946
  }
@@ -739,12 +965,18 @@ function foldChunksReader<In, S>(
739
965
  }
740
966
 
741
967
  /**
968
+ * A sink that effectfully folds its input chunks with the provided function,
969
+ * termination predicate and initial state. `contFn` condition is checked only
970
+ * for the initial value and at the end of processing of each chunk. `f` and
971
+ * `contFn` must preserve chunking-invariance.
972
+ *
742
973
  * @tsplus static fncts.io.SinkOps foldChunksIO
743
974
  */
744
975
  export function makeFoldChunksIO<Env, Err, In, S>(
745
976
  z: Lazy<S>,
746
977
  contFn: Predicate<S>,
747
978
  f: (s: S, inp: Conc<In>) => IO<Env, Err, S>,
979
+ __tsplusTrace?: string,
748
980
  ): Sink<Env, Err, In, In, S> {
749
981
  return Sink.defer(new Sink(foldChunksIOReader(z(), contFn, f)));
750
982
  }
@@ -766,6 +998,8 @@ function foldChunksIOReader<Env, Err, In, S>(
766
998
  }
767
999
 
768
1000
  /**
1001
+ * A sink that folds its inputs with the provided function and initial state.
1002
+ *
769
1003
  * @tsplus static fncts.io.SinkOps foldLeft
770
1004
  */
771
1005
  export function makeFoldLeft<In, S>(z: Lazy<S>, f: (s: S, inp: In) => S): Sink<unknown, never, In, never, S> {
@@ -773,6 +1007,9 @@ export function makeFoldLeft<In, S>(z: Lazy<S>, f: (s: S, inp: In) => S): Sink<u
773
1007
  }
774
1008
 
775
1009
  /**
1010
+ * A sink that folds its input chunks with the provided function and initial
1011
+ * state. `f` must preserve chunking-invariance.
1012
+ *
776
1013
  * @tsplus static fncts.io.SinkOps foldLeftChunks
777
1014
  */
778
1015
  export function makeFoldLeftChunks<In, S>(
@@ -783,23 +1020,37 @@ export function makeFoldLeftChunks<In, S>(
783
1020
  }
784
1021
 
785
1022
  /**
1023
+ * A sink that effectfully folds its input chunks with the provided function
1024
+ * and initial state. `f` must preserve chunking-invariance.
1025
+ *
786
1026
  * @tsplus static fncts.io.SinkOps foldLeftChunksIO
787
1027
  */
788
1028
  export function makeFoldLeftChunksIO<R, E, In, S>(
789
1029
  z: Lazy<S>,
790
1030
  f: (s: S, inp: Conc<In>) => IO<R, E, S>,
1031
+ __tsplusTrace?: string,
791
1032
  ): Sink<R, E, In, In, S> {
792
1033
  return Sink.foldChunksIO(z, () => true, f);
793
1034
  }
794
1035
 
795
1036
  /**
1037
+ * A sink that effectfully folds its inputs with the provided function and
1038
+ * initial state.
1039
+ *
796
1040
  * @tsplus static fncts.io.SinkOps foldLeftIO
797
1041
  */
798
- export function makeFoldLeftIO<R, E, In, S>(z: Lazy<S>, f: (s: S, inp: In) => IO<R, E, S>): Sink<R, E, In, In, S> {
1042
+ export function makeFoldLeftIO<R, E, In, S>(
1043
+ z: Lazy<S>,
1044
+ f: (s: S, inp: In) => IO<R, E, S>,
1045
+ __tsplusTrace?: string,
1046
+ ): Sink<R, E, In, In, S> {
799
1047
  return Sink.foldIO(z, () => true, f);
800
1048
  }
801
1049
 
802
1050
  /**
1051
+ * A sink that effectfully folds its inputs with the provided function,
1052
+ * termination predicate and initial state.
1053
+ *
803
1054
  * @tsplus static fncts.io.SinkOps foldIO
804
1055
  */
805
1056
  export function makeFoldIO<R, E, In, S>(
@@ -854,12 +1105,18 @@ function foldIOReader<R, E, In, S>(
854
1105
  }
855
1106
 
856
1107
  /**
1108
+ * Creates a sink that effectfully folds elements of type `In` into a
1109
+ * structure of type `S` until `max` elements have been folded.
1110
+ *
1111
+ * Like {@link makeFoldWeightedIO}, but with a constant cost function of 1.
1112
+ *
857
1113
  * @tsplus static fncts.io.SinkOps foldUntilIO
858
1114
  */
859
1115
  export function makeFoldUntilIO<R, E, In, S>(
860
1116
  z: Lazy<S>,
861
1117
  max: Lazy<number>,
862
1118
  f: (s: S, inp: In) => IO<R, E, S>,
1119
+ __tsplusTrace?: string,
863
1120
  ): Sink<R, E, In, In, S> {
864
1121
  return Sink.foldIO<R, E, In, readonly [S, number]>(
865
1122
  [z(), 0],
@@ -869,6 +1126,22 @@ export function makeFoldUntilIO<R, E, In, S>(
869
1126
  }
870
1127
 
871
1128
  /**
1129
+ * Creates a sink that folds elements of type `In` into a structure of type
1130
+ * `S`, until `max` worth of elements (determined by the `costFn`) have been
1131
+ * folded.
1132
+ *
1133
+ * The `decompose` function will be used for decomposing elements that cause
1134
+ * an `S` aggregate to cross `max` into smaller elements.
1135
+ *
1136
+ *
1137
+ * Be vigilant with this function, it has to generate "simpler" values or the
1138
+ * fold may never end. A value is considered indivisible if `decompose` yields
1139
+ * the empty chunk or a single-valued chunk. In these cases, there is no other
1140
+ * choice than to yield a value that will cross the threshold.
1141
+ *
1142
+ * The {@link makeFoldWeightedDecomposeIO} allows the decompose function to return a
1143
+ * `IO` value, and consequently it allows the sink to fail.
1144
+ *
872
1145
  * @tsplus static fncts.io.SinkOps foldWeightedDecompose
873
1146
  */
874
1147
  export function makeFoldWeightedDecompose<In, S>(
@@ -877,6 +1150,7 @@ export function makeFoldWeightedDecompose<In, S>(
877
1150
  max: Lazy<number>,
878
1151
  decompose: (inp: In) => Conc<In>,
879
1152
  f: (s: S, inp: In) => S,
1153
+ __tsplusTrace?: string,
880
1154
  ): Sink<unknown, never, In, In, S> {
881
1155
  return Sink.defer(() => {
882
1156
  /**
@@ -939,6 +1213,17 @@ export function makeFoldWeightedDecompose<In, S>(
939
1213
  }
940
1214
 
941
1215
  /**
1216
+ * Creates a sink that effectfully folds elements of type `In` into a
1217
+ * structure of type `S`, until `max` worth of elements (determined by the
1218
+ * `costFn`) have been folded.
1219
+ *
1220
+ * The `decompose` function will be used for decomposing elements that cause
1221
+ * an `S` aggregate to cross `max` into smaller elements. Be vigilant with
1222
+ * this function, it has to generate "simpler" values or the fold may never
1223
+ * end. A value is considered indivisible if `decompose` yields the empty
1224
+ * chunk or a single-valued chunk. In these cases, there is no other choice
1225
+ * than to yield a value that will cross the threshold.
1226
+ *
942
1227
  * @tsplus static fncts.io.SinkOps foldWeightedDecomposeIO
943
1228
  */
944
1229
  export function makeFoldWeightedDecomposeIO<R, E, In, S, R1, E1, R2, E2>(
@@ -947,6 +1232,7 @@ export function makeFoldWeightedDecomposeIO<R, E, In, S, R1, E1, R2, E2>(
947
1232
  max: Lazy<number>,
948
1233
  decompose: (inp: In) => IO<R2, E2, Conc<In>>,
949
1234
  f: (s: S, inp: In) => IO<R, E, S>,
1235
+ __tsplusTrace?: string,
950
1236
  ): Sink<R & R1 & R2, E | E1 | E2, In, In, S> {
951
1237
  return Sink.defer(() => {
952
1238
  function fold(
@@ -1007,6 +1293,15 @@ export function makeFoldWeightedDecomposeIO<R, E, In, S, R1, E1, R2, E2>(
1007
1293
  }
1008
1294
 
1009
1295
  /**
1296
+ * Creates a sink that folds elements of type `In` into a structure of type
1297
+ * `S`, until `max` worth of elements (determined by the `costFn`) have been
1298
+ * folded.
1299
+ *
1300
+ * @note
1301
+ * Elements that have an individual cost larger than `max` will force the
1302
+ * sink to cross the `max` cost. See {@link makeFoldWeightedDecompose} for a variant
1303
+ * that can handle these cases.
1304
+ *
1010
1305
  * @tsplus static fncts.io.SinkOps foldWeighted
1011
1306
  */
1012
1307
  export function makeFoldWeighted<In, S>(
@@ -1014,11 +1309,21 @@ export function makeFoldWeighted<In, S>(
1014
1309
  costFn: (s: S, inp: In) => number,
1015
1310
  max: Lazy<number>,
1016
1311
  f: (s: S, inp: In) => S,
1312
+ __tsplusTrace?: string,
1017
1313
  ): Sink<unknown, never, In, In, S> {
1018
1314
  return Sink.foldWeightedDecompose(z, costFn, max, Conc.single, f);
1019
1315
  }
1020
1316
 
1021
1317
  /**
1318
+ * Creates a sink that effectfully folds elements of type `In` into a
1319
+ * structure of type `S`, until `max` worth of elements (determined by the
1320
+ * `costFn`) have been folded.
1321
+ *
1322
+ * @note
1323
+ * Elements that have an individual cost larger than `max` will force the
1324
+ * sink to cross the `max` cost. See {@link makeFoldWeightedDecomposeIO} for a
1325
+ * variant that can handle these cases.
1326
+ *
1022
1327
  * @tsplus static fncts.io.SinkOps foldWeightedIO
1023
1328
  */
1024
1329
  export function makeFoldWeightedIO<R, E, In, S, R1, E1>(
@@ -1026,6 +1331,7 @@ export function makeFoldWeightedIO<R, E, In, S, R1, E1>(
1026
1331
  costFn: (s: S, inp: In) => IO<R, E, number>,
1027
1332
  max: Lazy<number>,
1028
1333
  f: (s: S, inp: In) => IO<R1, E1, S>,
1334
+ __tsplusTrace?: string,
1029
1335
  ): Sink<R & R1, E | E1, In, In, S> {
1030
1336
  return Sink.foldWeightedDecomposeIO(z, costFn, max, (inp) => IO.succeedNow(Conc.single(inp)), f);
1031
1337
  }
@@ -1105,6 +1411,8 @@ export function matchSink_<R, E, In, L, Z, R1, E1, In1 extends In, L1, Z1, R2, E
1105
1411
  }
1106
1412
 
1107
1413
  /**
1414
+ * Switch to another sink in case of failure
1415
+ *
1108
1416
  * @tsplus fluent fncts.io.Sink orElse
1109
1417
  */
1110
1418
  export function orElse<R, E, In, L, Z, R1, E1, In1, L1, Z1>(
@@ -1116,6 +1424,9 @@ export function orElse<R, E, In, L, Z, R1, E1, In1, L1, Z1>(
1116
1424
  }
1117
1425
 
1118
1426
  /**
1427
+ * Provides the sink with its required environment, which eliminates its
1428
+ * dependency on `R`.
1429
+ *
1119
1430
  * @tsplus fluent fncts.io.Sink provideEnvironment
1120
1431
  */
1121
1432
  export function provideEnvironment<R, E, In, L, Z>(
@@ -1127,22 +1438,30 @@ export function provideEnvironment<R, E, In, L, Z>(
1127
1438
  }
1128
1439
 
1129
1440
  /**
1441
+ * Runs both sinks in parallel on the input, returning the result or the
1442
+ * error from the one that finishes first.
1443
+ *
1130
1444
  * @tsplus fluent fncts.io.Sink race
1131
1445
  */
1132
1446
  export function race<R, E, In, L, Z, R1, E1, In1, L1, Z1>(
1133
1447
  self: Sink<R, E, In, L, Z>,
1134
1448
  that: Lazy<Sink<R1, E1, In1, L1, Z1>>,
1449
+ __tsplusTrace?: string,
1135
1450
  ): Sink<R & R1, E | E1, In & In1, L | L1, Z | Z1> {
1136
1451
  return self.raceBoth(that).map((result) => result.value);
1137
1452
  }
1138
1453
 
1139
1454
  /**
1455
+ * Runs both sinks in parallel on the input, returning the result or the error
1456
+ * from the one that finishes first.
1457
+ *
1140
1458
  * @tsplus fluent fncts.io.Sink raceBoth
1141
1459
  */
1142
1460
  export function raceBoth<R, E, In, L, Z, R1, E1, In1, L1, Z1>(
1143
1461
  self: Sink<R, E, In, L, Z>,
1144
1462
  that: Lazy<Sink<R1, E1, In1, L1, Z1>>,
1145
1463
  capacity: Lazy<number> = () => 16,
1464
+ __tsplusTrace?: string,
1146
1465
  ): Sink<R & R1, E | E1, In & In1, L | L1, Either<Z, Z1>> {
1147
1466
  return self.raceWith(
1148
1467
  that,
@@ -1153,6 +1472,9 @@ export function raceBoth<R, E, In, L, Z, R1, E1, In1, L1, Z1>(
1153
1472
  }
1154
1473
 
1155
1474
  /**
1475
+ * Runs both sinks in parallel on the input, using the specified merge
1476
+ * function as soon as one result or the other has been computed.
1477
+ *
1156
1478
  * @tsplus fluent fncts.io.Sink raceWith
1157
1479
  */
1158
1480
  export function raceWith<R, E, In, L, Z, R1, E1, In1, L1, Z1, R2, E2, Z2, R3, E3, Z3>(
@@ -1184,6 +1506,8 @@ export function raceWith<R, E, In, L, Z, R1, E1, In1, L1, Z1, R2, E2, Z2, R3, E3
1184
1506
  }
1185
1507
 
1186
1508
  /**
1509
+ * Accesses the specified service in the environment of the effect.
1510
+ *
1187
1511
  * @tsplus static fncts.io.SinkOps service
1188
1512
  */
1189
1513
  export function service<S>(/** @tsplus auto */ tag: Tag<S>): Sink<Has<S>, never, unknown, never, S> {
@@ -1191,6 +1515,8 @@ export function service<S>(/** @tsplus auto */ tag: Tag<S>): Sink<Has<S>, never,
1191
1515
  }
1192
1516
 
1193
1517
  /**
1518
+ * Accesses the specified service in the environment of the sink.
1519
+ *
1194
1520
  * @tsplus static fncts.io.SinkOps serviceWith
1195
1521
  */
1196
1522
  export function serviceWith<S, Z>(
@@ -1201,6 +1527,9 @@ export function serviceWith<S, Z>(
1201
1527
  }
1202
1528
 
1203
1529
  /**
1530
+ * Accesses the specified service in the environment of the sink in the
1531
+ * context of an effect.
1532
+ *
1204
1533
  * @tsplus static fncts.io.SinkOps serviceWithIO
1205
1534
  */
1206
1535
  export function serviceWithIO<S, R, E, Z>(
@@ -1211,6 +1540,9 @@ export function serviceWithIO<S, R, E, Z>(
1211
1540
  }
1212
1541
 
1213
1542
  /**
1543
+ * Accesses the specified service in the environment of the sink in the
1544
+ * context of a sink.
1545
+ *
1214
1546
  * @tsplus static fncts.io.SinkOps serviceWithSink
1215
1547
  */
1216
1548
  export function serviceWithSink<S, R, E, In, L, Z>(
@@ -1228,11 +1560,16 @@ export function serviceWithSink<S, R, E, In, L, Z>(
1228
1560
  }
1229
1561
 
1230
1562
  /**
1563
+ * Splits the sink on the specified predicate, returning a new sink that
1564
+ * consumes elements until an element after the first satisfies the specified
1565
+ * predicate.
1566
+ *
1231
1567
  * @tsplus fluent fncts.io.Sink splitWhere
1232
1568
  */
1233
1569
  export function splitWhere<R, E, In, L extends In, Z>(
1234
1570
  self: Sink<R, E, In, L, Z>,
1235
1571
  p: Predicate<In>,
1572
+ __tsplusTrace?: string,
1236
1573
  ): Sink<R, E, In, In, Z> {
1237
1574
  return new Sink(
1238
1575
  Channel.fromIO(Ref.make<Conc<In>>(Conc.empty())).flatMap((ref) =>
@@ -1280,6 +1617,8 @@ function splitter<R, E, In>(
1280
1617
  }
1281
1618
 
1282
1619
  /**
1620
+ * A sink that immediately ends with the specified value.
1621
+ *
1283
1622
  * @tsplus static fncts.io.SinkOps succeed
1284
1623
  */
1285
1624
  export function succeed<Z>(z: Lazy<Z>, __tsplusTrace?: string): Sink<unknown, never, unknown, never, Z> {
@@ -1287,6 +1626,8 @@ export function succeed<Z>(z: Lazy<Z>, __tsplusTrace?: string): Sink<unknown, ne
1287
1626
  }
1288
1627
 
1289
1628
  /**
1629
+ * A sink that immediately ends with the specified value.
1630
+ *
1290
1631
  * @tsplus static fncts.io.SinkOps succeedNow
1291
1632
  */
1292
1633
  export function succeedNow<Z>(z: Z, __tsplusTrace?: string): Sink<unknown, never, unknown, never, Z> {
@@ -1294,6 +1635,9 @@ export function succeedNow<Z>(z: Z, __tsplusTrace?: string): Sink<unknown, never
1294
1635
  }
1295
1636
 
1296
1637
  /**
1638
+ * Summarize a sink by running an effect when the sink starts and again when
1639
+ * it completes
1640
+ *
1297
1641
  * @tsplus fluent fncts.io.Sink summarized
1298
1642
  */
1299
1643
  export function summarized<R, E, In, L, Z, R1, E1, B, C>(
@@ -1324,6 +1668,8 @@ export function timed<R, E, In, L, Z>(
1324
1668
  }
1325
1669
 
1326
1670
  /**
1671
+ * Creates a sink produced from an effect.
1672
+ *
1327
1673
  * @tsplus static fncts.io.SinkOps unwrap
1328
1674
  */
1329
1675
  export function unwrap<R, E, R1, E1, In, L, Z>(
@@ -1339,26 +1685,36 @@ export function unwrap<R, E, R1, E1, In, L, Z>(
1339
1685
  */
1340
1686
  export function unwrapScoped<R, E, R1, E1, In, L, Z>(
1341
1687
  scoped: Lazy<IO<Has<Scope> & R, E, Sink<R1, E1, In, L, Z>>>,
1688
+ __tsplusTrace?: string,
1342
1689
  ): Sink<R & R1, E | E1, In, L, Z> {
1343
1690
  return new Sink(Channel.unwrapScoped(scoped().map((sink) => sink.channel)));
1344
1691
  }
1345
1692
 
1346
1693
  /**
1694
+ * Feeds inputs to this sink until it yields a result, then switches over to
1695
+ * the provided sink until it yields a result, finally combining the two
1696
+ * results into a tuple.
1697
+ *
1347
1698
  * @tsplus fluent fncts.io.Sink zip
1348
1699
  */
1349
1700
  export function zip<R, E, In, L, Z, R1, E1, In1 extends In, L1 extends L, Z1>(
1350
1701
  self: Sink<R, E, In, L, Z>,
1351
1702
  that: Lazy<Sink<R1, E1, In1, L1, Z1>>,
1703
+ __tsplusTrace?: string,
1352
1704
  ): Sink<R & R1, E | E1, In & In1, L | L1, readonly [Z, Z1]> {
1353
1705
  return self.zipWith(that, Function.tuple);
1354
1706
  }
1355
1707
 
1356
1708
  /**
1709
+ * Runs both sinks in parallel on the input and combines the results in a
1710
+ * tuple.
1711
+ *
1357
1712
  * @tsplus fluent fncts.io.Sink zipC
1358
1713
  */
1359
1714
  export function zipC<R, E, In, L, Z, R1, E1, In1 extends In, L1 extends L, Z1>(
1360
1715
  self: Sink<R, E, In, L, Z>,
1361
1716
  that: Lazy<Sink<R1, E1, In1, L1, Z1>>,
1717
+ __tsplusTrace?: string,
1362
1718
  ): Sink<R & R1, E | E1, In & In1, L | L1, readonly [Z, Z1]> {
1363
1719
  return self.zipWithC(that, Function.tuple);
1364
1720
  }
@@ -1374,6 +1730,7 @@ export function zipWith<R, E, In, L, Z, R1, E1, In1 extends In, L1 extends L, Z1
1374
1730
  self: Lazy<Sink<R, E, In, L, Z>>,
1375
1731
  that: Lazy<Sink<R1, E1, In1, L1, Z1>>,
1376
1732
  f: (z: Z, z1: Z1) => Z2,
1733
+ __tsplusTrace?: string,
1377
1734
  ): Sink<R & R1, E | E1, In & In1, L | L1, Z2> {
1378
1735
  return Sink.defer(self().flatMap((z) => that().map((z1) => f(z, z1))));
1379
1736
  }
@@ -1388,6 +1745,7 @@ export function zipWithC<R, E, In, L, Z, R1, E1, In1, L1, Z1, Z2>(
1388
1745
  self: Lazy<Sink<R, E, In, L, Z>>,
1389
1746
  that: Lazy<Sink<R1, E1, In1, L1, Z1>>,
1390
1747
  f: (z: Z, z1: Z1) => Z2,
1748
+ __tsplusTrace?: string,
1391
1749
  ): Sink<R & R1, E | E1, In & In1, L | L1, Z2> {
1392
1750
  return Sink.defer(
1393
1751
  self().raceWith(