Skip to content

FlatMappedArbitrary

Rasuvaeff\PropertyTesting\Arbitrary\FlatMappedArbitrary

ClassPackage: property-testing-coreSourceVersion: v0.1.0-12-g86ead85

Implements: ArbitraryInterface

Type parameters:

  • TInner of mixed = mixed
  • TOutput 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

php
__construct(
    \ArbitraryInterface<\Arbitrary\TInner> $inner,
    callable $flatMap,
)
ParameterTypeDefaultDescription
$inner\ArbitraryInterface<\Arbitrary\TInner>required
$flatMapcallablerequired

Methods

generate()

php
generate(Random $random): Shrinkable

Produce 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.