| 864 | * @since 2.0.0 |
| 865 | */ |
| 866 | export const foldUntil = <S, In, E = never, R = never>( |
| 867 | s: LazyArg<S>, |
| 868 | max: number, |
| 869 | f: (s: S, input: In) => Effect.Effect<S, E, R> |
| 870 | ): Sink<S, In, In, E, R> => { |
| 871 | const count = Count.normalize(max) |
| 872 | if (count === 0) return sync(s) |
| 873 | return fold<readonly [S, number], In, E, R>( |
| 874 | () => [s(), 0], |
| 875 | (tuple) => tuple[1] < count, |
| 876 | ([output, consumed], input) => Effect.map(f(output, input), (s) => [s, consumed + 1] as const) |
| 877 | ).pipe( |
| 878 | map((tuple) => tuple[0]) |
| 879 | ) |
| 880 | } |
| 881 | |
| 882 | /** |
| 883 | * A sink that returns whether all elements satisfy the specified predicate. |