%fn% {matchr}R Documentation

Create Function

Description

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

Usage

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

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)


[Package matchr version 0.1.0 Index]