Overview
A function stack is a sequence of multiple functions applied one after another. The |>(%)
pipeline operator applies multiple transformations to the data in a chain, making it cleaner and more readable.
Functions stacks are used as a sequencer to apply multiple functions one after another (|>
being the separator) on the output value (%
) of the previous function. Think of it as numbered instructions for a cooking recipe, where you must do step one before moving to step two.
Tines references
Before getting started, we recommend familiarizing yourself with the surrounding functionality this article covers:
Make it happen
Scenario
Map user names in an array, then sort them alphabetically.
Copy (
CMD + c
) the JSON block provided below and paste (CMD + v
) it onto the storyboard (these are action tiles and will auto-populate!).Click the “Users” action tile.
Review the JSON structure of this action via the Payload Builder in the right config panel to familiarize yourself with the data it will pass.
Click the “Pull names and sort alphabetically” action tile.
Review the Payload Builder of this action as well. Notice how the formula stack utilizes the
MAP
function, which pulls the list of “name” values from the array, then theSORT
function to sort the names alphabetically. The logic of these functions is separated by the|>
and the%
is used to reference the output of the first function (MAP
) in the stack to be used in theSORT
function.Click back to the “Users” action tile.
Click Run.
Once the flow has finished, compare the Events of both actions and see how the function stack worked to transform the data.
Actions
{"standardLibVersion":"81","actionRuntimeVersion":"32","agents":[{"disabled":false,"name":"Users","description":null,"options":"{\"mode\":\"message_only\",\"loop\":false,\"payload\":[{\"id\":\"01\",\"name\":\"Hanna\",\"team\":\"CSM\"},{\"id\":\"02\",\"name\":\"Shelby\",\"team\":\"CSE\"},{\"id\":\"03\",\"name\":\"Ray\",\"team\":\"Training\"},{\"id\":\"04\",\"name\":\"Daniel\",\"team\":\"Support\"}]}","position":{"x":690,"y":750},"type":"eventTransformation","timeSavedUnit":"minutes","timeSavedValue":0,"monitorAllEvents":false,"monitorFailures":false,"monitorNoEventsEmitted":null,"caseConfiguration":{"subStatus":null,"tags":[]},"recordType":null,"recordWriters":[],"form":null,"createdFromTemplateGuid":null,"createdFromTemplateVersion":null,"templateTags":[],"originStoryIdentifier":"cloud:0a13dfc5dbb71212cab0ad314b7fe531:f0064f807ac02bf877a6ff31d9b76916"},{"disabled":false,"name":"Pull names and sort alphabetically","description":null,"options":"{\"mode\":\"message_only\",\"loop\":false,\"payload\":\"=MAP(users, \\\"name\\\") |> SORT(%)\"}","position":{"x":690,"y":825},"type":"eventTransformation","timeSavedUnit":"minutes","timeSavedValue":0,"monitorAllEvents":false,"monitorFailures":false,"monitorNoEventsEmitted":null,"caseConfiguration":{"subStatus":null,"tags":[]},"recordType":null,"recordWriters":[],"form":null,"createdFromTemplateGuid":null,"createdFromTemplateVersion":null,"templateTags":[],"originStoryIdentifier":"cloud:0a13dfc5dbb71212cab0ad314b7fe531:f0064f807ac02bf877a6ff31d9b76916"}],"links":[{"sourceIdentifier":"0","receiverIdentifier":"1"}],"diagramNotes":[]}