MCPcopy Create free account
hub / github.com/Effect-TS/effect / unfold

Function unfold

packages/effect/src/Array.ts:4339–4352  ·  view source on GitHub ↗
(b: B, f: (b: B) => Option.Option<readonly [A, B]>)

Source from the content-addressed store, hash-verified

4337 * @since 2.0.0
4338 */
4339export const unfold = <B, A>(b: B, f: (b: B) => Option.Option<readonly [A, B]>): Array<A> => {
4340 const out: Array<A> = []
4341 let next: B = b
4342 while (true) {
4343 const o = f(next)
4344 if (Option.isNone(o)) {
4345 break
4346 }
4347 const [a, b] = o.value
4348 out.push(a)
4349 next = b
4350 }
4351 return out
4352}
4353
4354/**
4355 * Creates an `Order` for arrays based on an element `Order`. Arrays are

Callers

nothing calls this directly

Calls 2

pushMethod · 0.80
fFunction · 0.50

Tested by

no test coverage detected