Collections
A collection is a list of values, such as names, invoice records, or amounts. Collection helpers answer common questions about that list: which invoices are pending, how each name should be cleaned, or what the amounts add up to. They return values without changing the source list.
The snippets below show only the expression being described. Use an expression after equals, Print, or Respond with in a program. Read Variables and Data Types for lists and records; the final example shows how to combine several helpers.
Basic List Operations
Section titled “Basic List Operations”list of 10, 20, 30, 40, and 50
count of itemsfirst of itemslast of itemsSorting and Reordering
Section titled “Sorting and Reordering”sort itemsreverse itemsunique itemsflatten nested_listFilter and Reject
Section titled “Filter and Reject”Select or exclude items based on a condition.
filter invoices where amount >= 1000reject invoices where amount >= 1000The where clause uses the same comparison syntax as If statements.
Return the first item matching a condition.
find invoices where status equals "pending"Transform each item in a list.
map names to trim itemmap names to uppercase itemThe word item refers to the current element during transformation. Callbacks accept arithmetic and boolean expressions, and record fields can be read explicitly with amount of item. The callback binding shares the flat variable namespace and overwrites an outer variable named item.
Reduce
Section titled “Reduce”Accumulate a list into a single value.
reduce amounts starting at 0 with sum and item to sum plus itemThe pattern is: reduce <list> starting at <initial> with <accumulator> and <item> to <expression>.
Group and Index
Section titled “Group and Index”Organize items by a field value.
group invoices by statusindex invoices by invoice_idgroup returns a record where each key maps to a list of matching items. index returns a record where each key maps to a single item.
Partition
Section titled “Partition”Split a list into two based on a condition.
partition invoices where amount >= 1000# Returns a record with "matches" and "rest" listsTake and Drop
Section titled “Take and Drop”Select a subset from the beginning or skip elements.
take 3 of invoicesdrop 3 of invoicesSplit a list into fixed-size groups.
chunk invoices by 10Combine two lists element-wise into pairs.
zip names and scoresSet Operations
Section titled “Set Operations”Combine lists using set logic.
union of list_a and list_bintersection of list_a and list_bdifference of list_a and list_bAny and All
Section titled “Any and All”Test whether items in a list satisfy a condition.
any of tasks where priority equals "urgent"all of tasks where status equals "done"Aggregation
Section titled “Aggregation”Numeric summaries over lists.
sum of amountsaverage of amountsmaximum of amountsminimum of amountsChaining Operations
Section titled “Chaining Operations”Operations compose naturally by assigning intermediate results:
active equals filter projects where status equals "active"sorted_active equals sort activetop_five equals take 5 of sorted_active