Iterator

The Iterator component is a generic component that allows users to iterate over an array of data.

#Release Stage

Alpha

#Configuration

To configure an Iterator, you need to specify three pieces of information

NameKeyTypeDescription
Input (required)inputstringThe data you want to iterate over
Components (required)componentarray[object]Array of components
Output Elements (required)output-elementsobjectOutput of the iterator

#Input

The input data is what you want to iterate over. For example, if a variable is text-array with the format array:strint, you can configure the iterator with input: ${variable.text-array}.

#Range

In addition to using input to iterate over all elements in an array, users can also specify a range. The range consists of three values: start, stop, and an optional step.

There are two representations for the range setting:

#Array Representation


range: [0, 5, 2]
---
range:
- 0
- 5
- 2

#Map Representation


range:
start: 0
stop: 5
step: 2

You can also use reference syntax within the range. For example:


range:
start: 0
stop: ${variable.top-k}
step: 2

#Component

The component dictionary mirrors the structure of the component dictionary in the pipeline recipe. You can include multiple components inside the Iterator. The key difference is that components within the Iterator can use the element of the Iterator as input, by referencing ${iterator.element}.

#Output Elements

The output-elements is a map of string-to-string. It specifies the output of the Iterator, and the Iterator will concatenate the results into an array. For example, in the following recipe, the Iterator collects the ${base64.output.data} from each iteration and merges them into an array.

#Example Recipe


variable:
text-array:
title: Text Array
type: array:string
output:
result-0:
title: Result 0
value: ${iterator-0.output.result}
result-1:
title: Result 1
value: ${iterator-1.output.result}
component:
iterator-0:
type: iterator
input: ${variable.text-array}
component:
base64-encode-0:
type: base64
task: TASK_ENCODE
input:
data: ${iterator-0.element}
output-elements:
result: ${base64-encode-0.output.data}
iterator-1:
type: iterator
range: [0,2]
component:
base64-encode-1:
type: base64
task: TASK_ENCODE
input:
data: ${variable.text-array[i]}
output-elements:
result: ${base64-encode-1.output.data}