Description Usage Arguments Value Functions Examples
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.
1 2 3 4 5 | 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.
1 2 3 4 5 6 7 8 9 | 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
test_pattern_(one, quote(ZERO)) # returns NULL
as.list(test_pattern_(one, quote(ONE(v)))) # returns a binding for v
as.list(test_pattern(two, TWO(v,w))) # returns a binding for v and w
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.