Collections
Devlish provides a rich set of list operations that read like English sentences. All collection operations return new values without mutating the original.
Basic List Operations
Section titled “Basic List Operations”items equals list of 10, 20, 30, 40, and 50
item_count equals count of itemsfirst_item equals first of itemslast_item equals last of itemsSorting and Reordering
Section titled “Sorting and Reordering”sorted equals sort itemsreversed equals reverse itemsno_dupes equals unique itemsflat equals flatten nested_listFilter and Reject
Section titled “Filter and Reject”Select or exclude items based on a condition.
large_invoices equals filter invoices where amount >= 1000small_invoices equals reject invoices where amount >= 1000The 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 itemupper_names equals map names to uppercase itemThe word item refers to the current element during transformation.
Reduce
Section titled “Reduce”Accumulate a list into a single value.
total equals 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.
by_status equals group invoices by statusindexed equals index 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.
result equals 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.
first_three equals take 3 of invoicesremaining equals drop 3 of invoicesSplit a list into fixed-size groups.
batches equals chunk invoices by 10Combine two lists element-wise into pairs.
paired equals zip names and scoresSet Operations
Section titled “Set Operations”Combine lists using set logic.
all_items equals union of list_a and list_bcommon equals intersection of list_a and list_bonly_in_a equals difference of list_a and list_bAny and All
Section titled “Any and All”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"Aggregation
Section titled “Aggregation”Numeric summaries over lists.
total equals sum of amountsavg equals average of amountshighest equals maximum of amountslowest equals minimum 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