Prelude API
    Preparing search index...

    Function fibonacci

    • Creates an infinite generator that yields the Fibonacci sequence.

      Parameters

      • a: number = 0

        First starting value, defaults to 0

      • b: number = 1

        Second starting value, defaults to 1

      Returns Generator<number, never, unknown>

      An infinite generator of Fibonacci numbers

      Fibonacci numbers in sequence

      // Generate standard Fibonacci sequence
      const fib = fibonacci()
      const first8 = Array.from({ length: 8 }, () => fib.next().value)
      // Result: [1, 1, 2, 3, 5, 8, 13, 21]
      // Generate Fibonacci sequence with custom starting values
      const fib = fibonacci(2, 3)
      const first6 = Array.from({ length: 6 }, () => fib.next().value)
      // Result: [3, 5, 8, 13, 21, 34]