Test if a value, expr, created from constructors matches a pattern of
constructors. The test_pattern_ function requires that
test_expr is a quoted expression while the test_pattern
function expects a bare expression and will quote it itself.
test_pattern_(expr, test_expr, eval_env = rlang::caller_env(), match_parent_env = rlang::caller_env()) test_pattern(expr, test_expr, eval_env = rlang::caller_env(), match_parent_env = rlang::caller_env())
| expr | A value created using constructors. |
|---|---|
| test_expr | A constructor pattern to test |
| eval_env | The environment where constructors can be found. |
| match_parent_env | Environment to use as the parent of the match bindings we return. This parameter enables you provide additional values to the environment where match-expressions are evaluated. |
NULL if the pattern does not match or an environment with
bound variables if it does.
test_pattern_: Version that quotes test_expr itself.
test_pattern: Version that quotes test_expr itself.
type := ZERO | ONE(x) | TWO(x,y) zero <- ZERO one <- ONE(1) two <- TWO(1,2) as.list(test_pattern(zero, ZERO)) # returns an empty binding#> list()#> NULL#> $v #> [1] 1 #>#> $v #> [1] 1 #> #> $w #> [1] 2 #>