Prelude API
    Preparing search index...

    Function retain

    • Wraps a generator to retain its state for a specified number of return operations. This is useful when you want to keep a generator alive through operations that would normally terminate it.

      Type Parameters

      • T = unknown

        Element type

      • TReturn = unknown

        Return type

      • TNext = unknown

        Next type

      Parameters

      • g: Generator<T>

        The generator to retain

      • count: number = 1

        Number of return operations to intercept before forwarding to original generator (default: 1)

      Returns Generator<T, TReturn | undefined, TNext>

      A wrapped generator that retains state for the specified count of return operations

      // Useful in composition when you need to preserve generator state
      const gen = G.retain(myGenerator, 2);
      // gen will survive 2 return() calls before terminating