generate: Compose generators

Description Usage Arguments See Also Examples

View source: R/gen.R

Description

Use 'generator' with a for loop over the output of another generator to create a new, more interesting generator.

Usage

1
generate(loop)

Arguments

loop

A 'for' loop expression, where the value iterated over is another Hedgehog generator.

See Also

[gen-monad()] for FP style ways of sequencing generators. This function is syntactic sugar over 'gen.and_then' to make it palatable for R users.

Examples

1
2
3
4
gen_squares   <- generate(for (i in gen.int(10)) i^2)
gen_sq_digits <- generate(for (i in gen_squares) {
  gen.c(of = i, gen.element(1:9))
})

hedgehog documentation built on May 2, 2019, 11:27 a.m.