I'll Be Backend
Principles

Imperative to Declarative: Loops into Pipelines

Imperative code says how: walk the list, keep a temporary list, add, break. Declarative code says what you want, as a collection pipeline where filter, map, sort, distinct and limit each do one job. These lessons take a sales report with two loops, turn each loop into a pipeline, give the sale rule one named home, and make a new rule from Finance a one-line edit.

Pick your language

When to use it

Use it when

A loop filters, transforms or totals a collection, and you want each job readable on its own line.

Skip it when

Each step depends on the one before it, like a running balance that stops at the first overdraft. The loop says that more plainly than a reduce.

Spot it by

A temporary list filled in a loop, a running total, a break or a flag that stops early.