| 721 | * @see {@link forEach} for consuming all input while running an effect for each element |
| 722 | * |
| 723 | * @category constructors |
| 724 | * @since 2.0.0 |
| 725 | */ |
| 726 | export const drain: Sink<void, unknown> = fromTransform((upstream) => |
| 727 | Pull.catchDone( |
| 728 | Effect.forever(upstream, { disableYield: true }), |
| 729 | () => endVoid |
| 730 | ) |
| 731 | ) |
| 732 | |
| 733 | /** |
| 734 | * A sink that folds its inputs with the provided function, termination |
| 735 | * predicate and initial state. |
| 736 | * |
| 737 | * **When to use** |
| 738 | * |
| 739 | * Use to accumulate stream input element by element with an effectful step and |
| 740 | * stop based on the accumulated state. |
| 741 | * |
| 742 | * **Details** |
| 743 | * |
| 744 | * The initial state is evaluated lazily. Each input element is folded with the |
| 745 | * effectful function, and the sink continues while `contFn` returns `true`. If |
| 746 | * the sink stops in the middle of a pulled array, the remaining elements from |
| 747 | * that array are returned as leftovers. |
| 748 | * |