FlatMappedArbitrary
Rasuvaeff\PropertyTesting\Arbitrary\FlatMappedArbitrary
Class — Package: property-testing-core — Source — Version: v0.1.0-12-g86ead85
Implements: ArbitraryInterface
Type parameters:
TInner of mixed = mixedTOutput of mixed = mixed
Dependent generators (monadic bind): each value produced by the source arbitrary is fed into a closure that returns the arbitrary generating the final value. Use it when one input's domain depends on another, e.g. a list plus a valid index into that list — instead of discarding invalid pairs via Assume::that().
Shrinking works on both levels: first the source value shrinks (the closure is re-applied and the dependent arbitrary regenerates with the same captured seed, so runs stay reproducible), then the dependent value shrinks through its own tree with the source value held fixed. The closure must be pure — it runs once per generated value and once per visited source candidate.
Constructor
__construct(
\ArbitraryInterface<\Arbitrary\TInner> $inner,
callable $flatMap,
)| Parameter | Type | Default | Description |
|---|---|---|---|
$inner | \ArbitraryInterface<\Arbitrary\TInner> | required | |
$flatMap | callable | required |
Methods
generate()
generate(Random $random): ShrinkableProduce one random value from this arbitrary's space, together with its shrink tree. Candidates must be ordered most aggressive first (typically toward a zero/empty/identity element) and every branch of the tree must be finite, so shrinking terminates.
Documentation inherited from ArbitraryInterface.