View on GitHub

formula_compose

Chained formula executions

Description

Create a new Formula from a list of Formula.

maths

Result of previous Formula computation is used as parameter for the next one. So you can chain multiple operations.

Examples

$result:=formula_compose (Formula($1+1);Formula($1+2)).call(Null;0) // (0 + 1) + 2 = 3

// or using collection
$formulas:=New collection(Formula($1+1);Formula($1+2)) // add one then add 2
$result:=formula_compose ($formulas).call(Null;0) // (0 + 1) + 2 = 3
$result:=formula_compose (Formula($1+1);Formula($1+2);Formula(String($1))).call(Null;0) // String((0 + 1) + 2) = "3"

Assigning to an object

$operation:=New object("compute";formula_compose ($formulas))
$result:=$operation.compute(3) // (3 + 1) + 2 = 5

Unit Tests

test_formula_compose