Integrated Dynamics - On the Dynamics of Integration

Functions

As Operator are first-class citizens in Integrated Dynamics logic, they can also be created as JavaScript functions.

Any way of creating JavaScript functions can be used to create Operators, such as via the function keyword, or by creating custom lambdas.

Functions accept a number of arguments, which –when executed through Integrated Dynamics logic– will receive regular Integrated Dynamics values that are translated into JavaScript values.

Binding JavaScript functions to a Variable Card as Operator, is done just like with constants and variables, by selecting the function member name in the Scripting Terminal text editor and binding it to a Variable Card. This value can now be used anywhere an Operator is accepted.

For example, you can create a function with a single Item argument that returns a Boolean to use as filter Operator for filtering a list of items that you read from a Chest.

Below, you can find examples of different types of functions that could be created.

function isEven(value) {
  return value % 2 === 0;
}

const isOdd = (value) => value % 2 !== 0;
function fibonacci(limit) {
  const values = [];
  let n1 = 0;
  let n2 = 1;
  let nextTerm = 0;
  for (let i = 1; i <= number; i++) {
    values.push(n1);
    nextTerm = n1 + n2;
    n1 = n2;
    n2 = nextTerm;
  }
  return values;
}