Scope Shapes
Curly brackets and related scopes.
Scope shapes are used in Frends to both logically separate functionality into different blocks, as well as perform iteration.
Scope shape is used to define a named scope within a Process, allowing for example error handling to catch errors from that area of Process specifically, and not interrupting the whole Process execution. It can be thought of as using curly brackets in standard programming.

Similarly to default Scope shape, Foreach and While Scope shapes are used create a scope within your Process, but in addition they perform Foreach and While iterations like their name implies. Foreach can be used to iterate over a whole array or list of items and perform actions for each element sequentially, while the While shape can be used to iterate until the specified condition no longer holds true. As a safeguard to avoid infinite loops, the While shape includes a max iterations field, which will raise an error in case the specified number of iterations is reached.
Scope
Scope shape can be used to surround and encapsulate a part of your Process, most commonly to logically divide your Process into sections, as well as for error handling purposes. It can also be used to define and name a specific operation within your Process, that returns a value afterwards.
If execution of a Scope is interrupted by an error, the execution will exit the Scope immediately, much like a Process's execution will stop to an error. With Scope shape, you can attach a Catch shape to it to avoid the error propagating and interrupting the whole Process execution, giving you a chance to recover from the error within the Process, or handle it more gracefully.
Foreach
To perform iteration in Frends Processes, you can use Foreach shape to loop through a container's elements one by one. The shape will take care that all elements in the container object are handled, and provides the current element as a variable within the Scope.
Much like in general programming, Foreach iteration cannot be used to add or remove elements from the iterated object, but modifying the contents of the current element is possible.

While
Instead of iterating for a specified number of times or for the length of a container object, While shape can be used to loop over and over again, until the condition no longer holds true. While the condition can also use incrementing number to execute specified amount of times, it can be more dynamic to allow execution as many times as needed, regardless of the actual number of iterations.

Because the condition is not directly connected to a container object's element count, it can be used to also add or remove elements from an object. The While shape can also be used to perform an API call until it succeeds, or wait and poll a system for a long running execution elsewhere.
To avoid situations where the condition will not ever change to false, called infinite loops, While shape includes a mandatory parameter to limit the number of iterations to a maximum value, making sure that the iteration will end eventually, if the condition does not change.
Last updated
Was this helpful?