/** * Constructs a `Chunk` by repeatedly applying the effectual function `f` as * long as it returns `Some`. * * @tsplus static effect/core/io/Effect.Ops unfold */ export function unfold( s: S, f: (s: S) => Effect> ): Effect> { return unfoldLoop(s, f, Chunk.empty()) } function unfoldLoop( s: S, f: (s: S) => Effect>, builder: Chunk ): Effect> { return f(s).flatMap((o) => { if (o.isSome()) { return unfoldLoop(o.value[1], f, builder.append(o.value[0])) } else { return Effect.succeed(builder) } }) }