all

Syntax

all(func, args...)

Arguments

func is a function.

args are the required parameters of func. They can be vectors/matrices/tables. They do not need to have the same data form, but they must have the same size. Data size is the number of elements for a vector, the number of columns for a matrix, and the number of rows for a table.

Details

Apply a function on each element of all arguments. The template runs through each element of a vector, each column of a matrix, and each row of a table. It stops execution and returns a false value as soon as one function call returns a false value. It returns a true value if all function calls return true values.

Examples

Template all on a vector:

x = 1 2 NULL 11 NULL 13 NULL 102 103;
y = x cut 3;
y;
// output
([1,2,],[11,,13],[,102,103])

all(hasNull, y);
// output
1
// check if all of [1,2,],[11,,13],[,102,103] has NULL values

x = 1 25 7 15 11 197 16 18 23;
y = x cut 3;
y;
// output
([1,25,7],[15,11,197],[16,18,23])

all(in, 7 11 23, y);
// output
1
// check if 7 in [1,25,7], 11 in [15,11,197], and 23 in [16,18,23]

all(in, 7 8 23, y);
// output
0
// return false as 8 is not in [15,11,197]

all(lt, 1 2 3, 4 5 6);
// output
1
// check if 1<4, 2<5 and 3<6

all(lt, 1 2 7, 4 5 6);
// output
0
// return false as 7<6 is false

Template all on a matrix. For a matrix, the template runs through each column.

x=1..6$2:3;
x;
#0 #1 #2
1 3 5
2 4 6
all(in, 1 4 5, x);
// output
1

all(in, 1 2 5, x);
// output
0
// return false as 2 is not in the second column of matrix x

Template all on a table. For a table, the template runs through each row. In the following example, we define a function varscompare to compare the values of 2 variables in a table.

x=table(1 2 3 as a, 4 5 6 as b);
x;
a b
1 4
2 5
3 6
def varscompare(t):t.a<t.b;
all(varscompare, x);
// output
1

y=table(1 7 3 as a, 4 5 6 as b);
// output
y;
a b
1 4
7 5
3 6
all(varscompare, y);
// output
0
// return false as 7<5 is false