/** * Constructs a `Chunk` by repeatedly applying the function `f` as long as it * returns `Some`. * * @tsplus static Chunk.Ops unfold */ export function unfold(s: S, f: (s: S) => Maybe): Chunk { let builder = Chunk.empty() let cont = true let s1 = s while (cont) { const x = f(s1) if (x.isSome()) { s1 = x[1] builder = builder.append(x[0]) } else { cont = false } } return builder }