CH07-L01 · applied

Chained transformations

Create helper maps, filter them, and transform the result into the required shape.

General CELRuns hereDocumented
What will I learn?

You can read a map() → filter() → map() chain as consecutive transformations of one list.

Where will I try it?

Directly below, in the browser playground.

What do I do?

Run both modes, compare where their values come from, then complete the task.

Try CEL · browser pilot

Try both ways to supply values

Define local values inside one CEL expression, or provide variables as JSON input. Everything runs in your browser.

CEL pilot subset
One self-contained CEL expressioncel.bind() gives a local name to a value and returns the result of the final expression.

cel.bind()cel.bind() is an optional official extension. It is not part of the core CEL language and may not be enabled by every host application.

Tip: press Ctrl/⌘ + Enter to run.
Result

Press Run CEL to evaluate the active example.

Pilot scope: literals, explicit conversions, local cel.bind() variables, JSON variables, lists, maps, presence, collection macros, core string checks, time values, arithmetic, comparisons, logic, and the conditional operator.

What you will do

Move one list through three clear stages: calculate helper data, select suitable items, and build the final result. Run the example in CEL only and then in CEL + JSON.

How it works

Every call in the chain receives the preceding call's result. The first map() creates a map containing a code and calculated total. filter() keeps orders worth at least 100. The final map() returns only their codes.

orders
  .map(order, {'code': order.code, 'total': order.price * order.quantity})
  .filter(row, row.total >= 100.0)
  .map(row, row.code)

Evaluation step by step

  1. Order A-10 becomes {'code': 'A-10', 'total': 100.0}.
  2. Order B-20 has a total of 54.0, so the filter removes it.
  3. C-30 has a total of 120.0 and remains.
  4. The final transformation returns ['A-10', 'C-30'].

The helper map is an ordinary CEL value. It does not modify the input order and exists only in that stage's result.

Your task

  1. Run the prepared expression.
  2. Change the threshold from 100.0 to 110.0.
  3. Return the whole helper map row instead of row.code in the final map().

Expected observation: The higher threshold keeps only C-30. Removing the final projection also exposes the calculated totals.

Common mistake

A macro variable exists only inside that macro's body. The name order is not available in the following filter(); that stage works with a new item named row.

Show the explanation

The first map() returns a new list of maps. The next macro reads those maps, not the original orders.

Knowledge check

What kind of list enters filter(), and what kind of list does the final map() return?

Key takeaway

Read a longer expression from left to right as a data flow. Give every stage one understandable job.

Sources

  • CEL-DEV — official overview of CEL and its collection macros.
  • CEL-LANG — official definition of lists, maps, and macros.
  • CEL-GO-BIND — official documentation for the optional cel.bind() extension used by the self-contained tab.