on: Transform a binary function with a unary function

Description Usage Arguments Details Value Examples

Description

Execute the binary function f on the results of applying unary function g to two arguments x and y.

Usage

1
f %on% g

Arguments

f

a binary function.

g

a unary function.

Details

Formally, %on% is defined this way : function(f, g) function(x, y) f(g(x), g(y)).

f can be a function taking two arguments but also a variadic function (i.e. whose first argument is ...), which will be fed with exactly two arguments.

A typical usage of this function is in combination with function like group_if.

Value

A binary function. This function transforms 2 inputs (with g) and combines the outputs (with f).

Examples

1
2
h <- max %on% abs
h(-2, 1)

Example output

[1] 2

funprog documentation built on Jan. 13, 2021, 11:52 a.m.