Function: letrec()
Call Signature
letrec<
T>(builder):LetrecValue<T>
Defined in: packages/fast-check/src/arbitrary/letrec.ts:90
For mutually recursive types
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
builder | T extends Record<string, unknown> ? LetrecTypedBuilder<T> : never | Arbitraries builder based on themselves (through tie) |
Returns
LetrecValue<T>
Example
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)
Remarks
Since 1.16.0
Call Signature
letrec<
T>(builder):LetrecValue<T>
Defined in: packages/fast-check/src/arbitrary/letrec.ts:110
For mutually recursive types
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
builder | LetrecLooselyTypedBuilder<T> | Arbitraries builder based on themselves (through tie) |
Returns
LetrecValue<T>
Example
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)
Remarks
Since 1.16.0