Jamie Balfour

Welcome to my personal website.

Find out more about me, my personal projects, reviews, courses and much more here.

Official ZPE/YASS documentationQuerying data with ZEQL

Overview

ZEQL (ZPE Expression Query Language, pronounced zequel) provides a concise way to filter and transform an iterable value. A query uses the familiar from, in, where and select keywords.

ZEQL queries are lazy. The source is enumerated when the result is consumed, not when the query is declared. A query variable exists only inside its query.

A first query

YASS
$numbers = [1, 2, 3, 4, 5]

$doubled = from $number in $numbers
  select $number * 2

print($doubled.to_list())
  

The expression following select is evaluated for every item. It can return the original value, a calculated value, or a value taken from an object or map.

Filtering with where

YASS
$numbers = [1, 2, 3, 4, 5, 6]

$even_squares = from $number in $numbers
  where $number % 2 == 0
  select $number * $number

print($even_squares.to_list()) //[4, 16, 36]
  

The optional where expression must produce a boolean. Values for which it returns false are skipped before the projection is evaluated.

Using query results

A ZEQL expression returns a ZPEExpressionQuery. It supports these operations:

to_list() ⇒ list
Enumerates the complete query and returns an ordinary list.
length() ⇒ number
Counts the values produced by the query.
first() ⇒ mixed
Returns the first matching value, or undefined when no value matches.

Because a query is lazy, enumerate it only when the result is needed. Use first() when only one match is required instead of converting the entire result to a list.

Related collection methods

Lists and maps also provide where, select and order_by methods for fluent collection pipelines:

YASS
$names = ["Jimmy", "James", "Jack", "John"]
$result = $names
  .where($name => string_contains($name, "a"))
  .select($name => $name)
  .order_by($name => $name)
  

ZEQL was made available in ZPE 1.14.9 (Spurriergate, September 2026).

Comments

There are no comments on this page.

New comment

Comments are welcome and encouraged, including disagreement and critique. However, this is not a space for abuse. Disagreement is welcome; personal attacks, harassment, or hate will be removed instantly. This site reflects personal opinions, not universal truths. If you can’t distinguish between the two, this probably isn’t the place for you. The system temporarily stores IP addresses and browser user agents for the purposes of spam prevention, moderation, and safeguarding. This data is automatically removed after fourteen days. Your email address is stored so that replies can be sent to your email address.

Comments powered by BalfComment

Feedback 👍
Comments are sent via email to me.