grapes-fn-grapes: Create Function

Description Usage Arguments Value Examples

Description

Syntactic sugar for creating a single-variable function. Can be conveniently used in Match statements.

Usage

1
lhs %fn% rhs

Arguments

lhs

symbol used to denote the function argument

rhs

expression that is converted to the function body. rhs may need to be surrounded by parentheses is other infix operators are used due to precedence rules.

Value

a function

Examples

1
2
3
4
5
6
7
8
9
Match(
  "abc",
  is.numeric  -> -1,
  i %fn% grepl("bc", i) -> 0,
  is.character -> 1
)

print_sq_log <- i %fn% print(sqrt(log(i)))
print_sq_log(10)

matchr documentation built on Sept. 9, 2021, 5:07 p.m.