Skip to content

Collections

Devlish provides a rich set of list operations that read like English sentences. All collection operations return new values without mutating the original.

items equals list of 10, 20, 30, 40, and 50
item_count equals count of items
first_item equals first of items
last_item equals last of items
sorted equals sort items
reversed equals reverse items
no_dupes equals unique items
flat equals flatten nested_list

Select or exclude items based on a condition.

large_invoices equals filter invoices where amount >= 1000
small_invoices equals reject invoices where amount >= 1000

The where clause uses the same comparison syntax as If statements.

Return the first item matching a condition.

pending_invoice equals find invoices where status equals "pending"

Transform each item in a list.

cleaned_names equals map names to trim item
upper_names equals map names to uppercase item

The word item refers to the current element during transformation.

Accumulate a list into a single value.

total equals 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.

by_status equals group invoices by status
indexed equals 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.

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

Select a subset from the beginning or skip elements.

first_three equals take 3 of invoices
remaining equals drop 3 of invoices

Split a list into fixed-size groups.

batches equals chunk invoices by 10

Combine two lists element-wise into pairs.

paired equals zip names and scores

Combine lists using set logic.

all_items equals union of list_a and list_b
common equals intersection of list_a and list_b
only_in_a equals difference of list_a and list_b

Test whether items in a list satisfy a condition.

has_urgent equals any tasks where priority equals "urgent"
all_complete equals all tasks where status equals "done"

Numeric summaries over lists.

total equals sum of amounts
avg equals average of amounts
highest equals maximum of amounts
lowest equals 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