grapes-plus-grapes: Function composition operator

Description Usage Arguments Value Examples

Description

Composite functions a and b into a(b(...)).

Usage

1
a %+% b

Arguments

a

A function that can be called with one argument.

b

A function that can be called with one or more argument, and result of b() can be passed to a().

Value

A new function, whose arguments are what b() can accept, and whose result is what a() can return.

Examples

1
2
3
4
5
6
7
8
lse <- log%+%sum%+%exp
lse(1:10)
#logsumexp(1:10)	# actual logsumexp() is more sophistic
log(sum(exp(1:10)))
sum <- sd
lse(1:10)	# lse() is fixed at definition
log(sum(exp(1:10)))
(log%+%sum%+%exp)(1:10)	# now is (log%+%sd%+%exp)

garray documentation built on May 1, 2019, 8:47 p.m.