( s: S, f: (s: S) => Effect.Effect<readonly [A, S] | undefined, E, R> )
| 1574 | * @since 2.0.0 |
| 1575 | */ |
| 1576 | export const unfold = <S, A, E, R>( |
| 1577 | s: S, |
| 1578 | f: (s: S) => Effect.Effect<readonly [A, S] | undefined, E, R> |
| 1579 | ): Stream<A, E, R> => |
| 1580 | fromPull(Effect.sync(() => { |
| 1581 | let state = s |
| 1582 | return Effect.flatMap(Effect.suspend(() => f(state)), (next) => { |
| 1583 | if (next === undefined) return Cause.done() |
| 1584 | state = next[1] |
| 1585 | return Effect.succeed(Arr.of(next[0])) |
| 1586 | }) |
| 1587 | })) |
| 1588 | |
| 1589 | /** |
| 1590 | * Creates a stream by repeatedly evaluating an effectful page function. |