Generator[T: T]¶
Wraps a GenObj with composition methods (map, filter, flat_map,
union). Shrinking is automatic through choice-sequence replay.
Implements¶
- GenObj[T] box
Constructors¶
create¶
Parameters¶
- gen: GenObj[T] box
Returns¶
- Generator[T] ref^
Public Functions¶
generate¶
Produce a random value from the given source of randomness.
Parameters¶
- rnd: Randomness ref
Returns¶
- T^ ?
filter¶
Only yield values for which predicate returns true.
Rejected values are retried up to 100 times. Each attempt is recorded in its own discardable span so the shrinker can remove the failed draws cleanly. Errors after exhausting retries.
Parameters¶
- predicate: {(T): (T^, Bool)}[T] box
Returns¶
- Generator[T] box
map[U: U]¶
Apply fn to each generated value.
Parameters¶
- fn: {(T): U^}[T, U] box
Returns¶
- Generator[U] box
flat_map[U: U]¶
For each value of this generator, create a generator that is then combined. Both outer and inner choices are in the same sequence, so shrinking the outer value works automatically.
Parameters¶
- fn: {(T): Generator[U]}[T, U] box
Returns¶
- Generator[U] box
union[U: U]¶
Produce the value of this generator or the other with equal probability.
Parameters¶
- other: Generator[U] box
Returns¶
- Generator[(T | U)] box