API Reference | fast-check | Property based testing framework
    Preparing search index...

    Function letrec

    • For mutually recursive types

      Type Parameters

      • T

      Parameters

      • builder: T extends Record<string, unknown> ? LetrecTypedBuilder<T<T>> : never

        Arbitraries builder based on themselves (through tie)

      Returns LetrecValue<T>

      type Leaf = number;
      type Node = [Tree, Tree];
      type Tree = Node | Leaf;
      const { tree } = fc.letrec<{ tree: Tree, node: Node, leaf: Leaf }>(tie => ({
      tree: fc.oneof({depthSize: 'small'}, tie('leaf'), tie('node')),
      node: fc.tuple(tie('tree'), tie('tree')),
      leaf: fc.nat()
      }));
      // tree is 50% of node, 50% of leaf
      // the ratio goes in favor of leaves as we go deeper in the tree (thanks to depthSize)

      Since 1.16.0

    • For mutually recursive types

      Type Parameters

      • T

      Parameters

      Returns LetrecValue<T>

      const { tree } = fc.letrec(tie => ({
      tree: fc.oneof({depthSize: 'small'}, tie('leaf'), tie('node')),
      node: fc.tuple(tie('tree'), tie('tree')),
      leaf: fc.nat()
      }));
      // tree is 50% of node, 50% of leaf
      // the ratio goes in favor of leaves as we go deeper in the tree (thanks to depthSize)

      Since 1.16.0