Skip to contents

Splices the steps of validator into restriction, so two independently defined validators combine into one. Splicing happens when the validator is built: print() shows one flat list of steps and there is no nesting at run time.

Usage

require_valid(restriction, validator)

Arguments

restriction

a restriction object.

validator

a restriction object whose steps are appended.

Value

The modified restriction object.

Details

If validator allows NULL (see allow_null()), its steps are skipped for a NULL value and the combined validator does not itself become NULL-tolerant.

Examples

id_v <- restrict("id") |> require_integer(no_na = TRUE)
pos_v <- restrict("x") |> require_positive(strict = TRUE)
restrict("id") |> require_valid(id_v) |> require_valid(pos_v)
#> <restriction id>
#>   1. must be whole number (no NA)
#>   2. must be positive