Using Expressions with Arrays and Objects
  • 22 Sep 2023
  • 4 Minutes to read
  • Contributors

Using Expressions with Arrays and Objects


Article summary

Learn the basics of working with arrays and objects in the Expressions Editor.

Knowing what Expressions to use in order to work with Arrays is essential for working with data in Tulip. You can also use expressions to break down Objects into separate data types. This allows you to focus on specific data to inform your process in an application.


Expressions with Arrays

There are several kinds of expressions that perform different functions to return values. These values can be a single value or another array. They can also be the same data type or a different data type.

Some expressions use arrays to return simple arithmetic values:

array_max()
Returns the maximum of a given numeric array

array_max expression

array_min()
Returns the minimum of a given numeric array

array_min expression

array_avg()
Returns the average of a given numeric array

array_avg expression

Array Expressions - Max Min Avg

Other expressions use standard deviation to return values.

array_stdev_population()
Returns the standard deviation of the population of a given numeric array

array_stdev_population expression

array_stdev_sample()
Returns the standard deviation of the sample of a given numeric array

array_stdev_sample expression

Array Expressions  - StDev Pop Samp

One of the most widely used expressions in the Tulip platform is:

array_index_of()
Returns the index of the first occurance of the given value in the given array. If not found, returns “-1”.

array_index_of expression

Array_Index_Of Ex

As explained in this community post, you can use array_index_of() to determine a COM port on a serial driver. You could also use it for Connector output results to find a particular work order.

There are also expressions that use arrays to determine given values, such as:

arraycontains()
Returns “true” if the given value is in the given array, returns “false” if otherwise

arraycontains expression yes

Array Expressions - Contains

The following expressions use regular expressions to return arrays. You can also use this cheatsheet to understand regex capabilities and syntax.

regex_match()
Returns an array of matches to the regular expression

regex_match expression ex

regex_match expression ex in app

regex_replace()
Returns a modified Array with string replacements defined in the expression

regex_replace expression ex

regex_replace expression ex in app

Finally, you can combine multiple arrays with similar data types to create a new array.

array_concat()
Concatenates any number of arrays of a single type into a single array of that type

Array_Concat Expression

Array_Concat Ex

Expressions with Objects

Expressions that use objects all perform the same function in Tulip: gathering information from one object into another object that uses the same data type. All of the following expressions work similarly, using a given key (header) to convert an object array to a base array.

NOTE: These expressions are mainly used with a Connector Function output.

map_to_boolean_list()
Converts an object array to a Boolean array for the given key

map_to_boolean_list expression ex

map_to_integer_list()
Converts an object array to an Integer array for the given key

map_to_integer_list expression ex

map_to_number_list()
Converts an object array to a Number array for the given key

map_to_number_list expression ex

map_to_text_list()
Converts an object array to a text array for the given key

map_to_text_list expression ex

In an application, this expression (and other map_to expressions) return the base array in the data type specified. Save it as a Variable so it appears as a list, as shown below.

 map_to_text_list expression ex in app

Using one of the above map_to_text expressions with array_index_of() allows you to extract information from Outputs.


Did you find what you were looking for?

You can also head to community.tulip.co to post your question or see if others have faced a similar question!


Was this article helpful?