Skip to content

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.

list of 10, 20, 30, 40, and 50
count of items
first of items
last of items
sort items
reverse items
unique items
flatten nested_list

Select or exclude items based on a condition.

filter invoices where amount >= 1000
reject invoices where amount >= 1000

The 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 item
map names to uppercase item

The 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.

Accumulate a list into a single value.

reduce amounts starting at 0 with sum and item to sum plus item

The pattern is: reduce <list> starting at <initial> with <accumulator> and <item> to <expression>.

Organize items by a field value.

group invoices by status
index invoices by invoice_id

group 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.

Split a list into two based on a condition.

partition invoices where amount >= 1000
# Returns a record with "matches" and "rest" lists

Select a subset from the beginning or skip elements.

take 3 of invoices
drop 3 of invoices

Split a list into fixed-size groups.

chunk invoices by 10

Combine two lists element-wise into pairs.

zip names and scores

Combine lists using set logic.

union of list_a and list_b
intersection of list_a and list_b
difference of list_a and list_b

Test whether items in a list satisfy a condition.

any of tasks where priority equals "urgent"
all of tasks where status equals "done"

Numeric summaries over lists.

sum of amounts
average of amounts
maximum of amounts
minimum of amounts

Operations compose naturally by assigning intermediate results:

active equals filter projects where status equals "active"
sorted_active equals sort active
top_five equals take 5 of sorted_active