MCPcopy
hub / github.com/Effect-TS/effect / fib

Function fib

packages/effect/test/Effect/stack-safety.test.ts:34–43  ·  view source on GitHub ↗
(
        n: number,
        a: BigInt = BigInt("0"),
        b: BigInt = BigInt("1")
      )

Source from the content-addressed store, hash-verified

32 it.effect("deep flatMap", () =>
33 Effect.gen(function*() {
34 const fib = (
35 n: number,
36 a: BigInt = BigInt("0"),
37 b: BigInt = BigInt("1")
38 ): Effect.Effect<BigInt, Error> => {
39 return pipe(
40 Effect.sync(() => ((a as any) + (b as any)) as BigInt),
41 Effect.flatMap((b2) => n > 0 ? fib(n - 1, b, b2) : Effect.succeed(b2))
42 )
43 }
44 const result = yield* (fib(1000))
45 const expected = BigInt(
46 "113796925398360272257523782552224175572745930353730513145086634176691092536145985470146129334641866902783673042322088625863396052888690096969577173696370562180400527049497109023054114771394568040040412172632376"

Callers 1

Calls 2

syncMethod · 0.80
pipeFunction · 0.50

Tested by

no test coverage detected