( s: S, f: (s: S) => Effect.Effect<readonly [A, S] | undefined, E, R> )
| 1449 | * @since 2.0.0 |
| 1450 | */ |
| 1451 | export const unfold = <S, A, E, R>( |
| 1452 | s: S, |
| 1453 | f: (s: S) => Effect.Effect<readonly [A, S] | undefined, E, R> |
| 1454 | ): Stream<A, E, R> => |
| 1455 | fromPull(Effect.sync(() => { |
| 1456 | let state = s |
| 1457 | return Effect.flatMap(Effect.suspend(() => f(state)), (next) => { |
| 1458 | if (next === undefined) return Cause.done() |
| 1459 | state = next[1] |
| 1460 | return Effect.succeed(Arr.of(next[0])) |
| 1461 | }) |
| 1462 | })) |
| 1463 | |
| 1464 | /** |
| 1465 | * Creates a stream by repeatedly evaluating an effectful page function. |