eachPost (:O)

Syntax

eachPost(func, X, [post])

or

<operator>:O Y

or

Y <operator>:O X

Arguments

func is a binary function.

X is a vector/matrix/table.

When X is a vector, post must be a scalar; when X is a matrix, post must be a vector; when X is a table, post must be a dictionary. When post is absent, the last element in the result would be NULL.

Details

Apply func over all pairs of consecutive elements of the object. It is equivalent to: F(X[0], X[1]), F(X[1], X[2]), …, F(X[n], post).

Examples

$ x=1..10;
$ eachPost(sub, x);
[-1,-1,-1,-1,-1,-1,-1,-1,-1,]
// equivalent to [1-2, 2-3, ..., 9-10, NULL]

$ +:O x;
[3,5,7,9,11,13,15,17,19,]
// equivalent to [1+2, 2+3, ..., 9+10, NULL]



$ x +:O 0;
[3,5,7,9,11,13,15,17,19,10]
// equivalent to [1+2, 2+3, ..., 9+10, 10+0]

$ x=1..12$3:4;
$ x;

col1

col2

col3

col4

1

4

7

10

2

5

8

11

3

6

9

12

$ -:O x;

col1

col2

col3

col4

-3

-3

-3

-3

-3

-3

-3

-3

-3

$ eachPost(\, x, x[0]);

col1

col2

col3

col4

0.25

0.571429

0.7

10

0.4

0.625

0.727273

5.5

0.5

0.666667

0.75

4