grapes-equals-greater-than-grapes: A JavaScript style of creating functions

Description Usage Arguments Value Examples

Description

A JavaScript style of creating functions

Usage

1
args %=>% expr

Arguments

args

function arguments: see formals

expr

R expression that forms the body of functions: see body

Value

A function that takes args as parameters and expr as the function body

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Formal arguments
c(a) %=>% {
  print(a)
}

# Informal arguments
list(a=) %=>% {
  print(a)
}

# Multiple inputs
c(a, b = 2, ...) %=>% {
  print(c(a, b, ...))
}

# ----- JavaScript style of forEach -----
# ### Equivalent JavaScript Code:
# LETTERS.forEach((el, ii) => {
#   console.log('The index of letter ' + el + ' in "x" is: ' + ii);
# });

iapply(LETTERS, c(el, ii) %=>% {
  cat2('The index of letter ', el, ' in ', sQuote('x'), ' is: ', ii)
}) -> results

dipsaus documentation built on Sept. 6, 2021, 5:08 p.m.