Sequences
Last updated
Was this helpful?
Last updated
Was this helpful?
A sequence is a composite data type representing an ordered list of values. If you are familiar with other programming languages, you may recognize sequences as "lists", "arrays", or (in some cases) "tables".
Sequences may be created using sequence expressions, comprising of an opening square bracket, a comma-separated list of elements, and a closing square bracket.
A sequence of records is known, by convention, as a table.
Sequences are typically used in conjunction with , and the .
You can also update (or rather, create an updated copy) of a sequence of records using the with keyword.
A with-expression may employ a guard expression to selectively update records:
Several update clauses may be specified in a comma-separated list. The first clause whose guard expression is true for a record will be used to update that record. The otherwise
guard expression always evaluates to true and must come last.
For sequences of records, it is possible to access each "column" by dot notation. This will return a sequence containing the value of the member on each element.
The name of a sequence type â as shown when you let the mouse cursor hover over a variable name in the Flow Designer â is created by appending an asterisk (*) to the type of the sequence's elements. In the example above, the variable xs contains numbers and therefore has the type number*
(pronounced "sequence of numbers"). The variable animals has the type {name: text, latinName: text}*
which is slightly more difficult to pronounce.
The type of a sequence is inferred from its elements. What, then, is the type of an empty sequence? Since there are no elements from which to infer an element type, FlowScript will choose the type nothing* for such a sequence. In conjunction with and , this ensures that the type of the empty sequence behaves well when combining with other, non-empty values.
What if we create a sequence where the elements have different types? In that case, the element type of the sequence will be the of all the elements.
Although the type of mix1 does not indicate the presence of a member labelled latinName, the member has not been erased. You can use to get it back: