Filter

The filter acts as a guard, allowing the processing flow under specific conditions and blocking it under others. It enables you to halt further data processing if a certain condition is unmet, or continue processing in a specific direction when the condition is satisfied.

Filters are akin to if...else and switch statements in traditional programming.

Filters fall under the category of function extensions. The addition or removal of filters follows the same procedure as with other extensions. Click on the + icon situated behind an output, modifier, or error handler, and choose the Filter option.

How it works

When a filter's calculation yields a true result, data processing proceeds beyond the filter. Conversely, if the filter produces a false result, data processing is halted. To configure the filter with expressions leading to true or false results, JavaScript operators and expressions, similar to the modifier, can be employed.

Understanding if a value is truthy or falsy is crucial. In Heisenware, we align with JavaScript's behavior, where certain values are interpreted as true or false. Falsy values, which produce a false inside the filter, include:

  • false

  • undefined

  • null

  • 0

  • ""

  • document.all

All values not listed as falsy are considered truthy. This includes all objects, such as functions and arrays, which are inherently truthy. JavaScript adheres strictly to these rules, where objects without properties or arrays with a length of 0 are still considered truthy. Notably, an empty string ("") and null are falsy, while a space (" ") and the string "null" are truthy.

Configuration

As previously mentioned, a filter can be configured using JavaScript operators and expressions, with the variable x representing the previous value. To explore available operators, refer to the JavaScript documentation and navigate to the sections on comparison operators and logical operators.

In the example below, four filters are attached to a function generating random integers. With the value 10, two filters evaluate to true, and two to false. Only the true filters, the first and the third, allow the subsequent modifier to process the data and calculate a new value.

Last updated