@hegeldev/hegel
    Preparing search index...

    Function recursive

    • Generate recursively structured data, such as trees or JSON documents, whose leaves come from base.

      extend receives a generator of sub-values (each a leaf or a further branch) and returns a generator combining some of them into one compound value; it is called afresh for each branch generated. Values range from a single leaf up to the limits of maxDepth (how deeply branches nest, default 32) and maxLeaves (the most leaves in one value, default 100: an attempt drawing more is discarded and drawn again, and the test case is rejected when several attempts in a row overrun). The engine decides where values branch, so recursive values are distributed the same way in every Hegel frontend. Values shrink toward a single leaf.

      A value prints as its leaves and branches do, through base and the generators extend returns, so it is printable when they are.

      Throws if maxDepth is negative or maxLeaves is less than 1. For mutually recursive definitions, use deferred.

      Type Parameters

      • T

      Parameters

      Returns PrintableGenerator<T>

      type Json = null | boolean | number | string | Json[];
      const json: Generator<Json> = recursive<Json>(
      oneOf<Json>(just(null), booleans(), floats(), text()),
      (children) => arrays(children, { maxSize: 5 }),
      );
    • Generate recursively structured data, such as trees or JSON documents, whose leaves come from base.

      extend receives a generator of sub-values (each a leaf or a further branch) and returns a generator combining some of them into one compound value; it is called afresh for each branch generated. Values range from a single leaf up to the limits of maxDepth (how deeply branches nest, default 32) and maxLeaves (the most leaves in one value, default 100: an attempt drawing more is discarded and drawn again, and the test case is rejected when several attempts in a row overrun). The engine decides where values branch, so recursive values are distributed the same way in every Hegel frontend. Values shrink toward a single leaf.

      A value prints as its leaves and branches do, through base and the generators extend returns, so it is printable when they are.

      Throws if maxDepth is negative or maxLeaves is less than 1. For mutually recursive definitions, use deferred.

      Type Parameters

      • T

      Parameters

      Returns Generator<T>

      type Json = null | boolean | number | string | Json[];
      const json: Generator<Json> = recursive<Json>(
      oneOf<Json>(just(null), booleans(), floats(), text()),
      (children) => arrays(children, { maxSize: 5 }),
      );