Blog

Reading code left to right

2 min read

Data moves through a web program in steps. A pipe operator lets the code read in the order the data moves, without a class for every step.

Most of what a web program does is move data through steps: rows from a query, filtered, sorted, cut to a page, turned into markup. Written as nested calls, the last step comes first:

render(take(sortBy(filter(rows, isPaid), byDate), 20))

Method chains fix the order, but only for the methods the type happens to have. Add your own step and you are back to wrapping.

The pipe

let page = orders    | filter((o) => o.paid)    | sort_by((o) => o.date)    | take(20)    | map((o) => <OrderRow order={o}/>)

x | f(a) is f(x, a): the value on the left becomes the first argument. Any function works as a step, the builtins and your own alike, so there is nothing to extend and no wrapper type. A line that starts with | carries on the line before, so a pipeline reads as a list of steps.

Small choices that follow

None of this is new. Elixir and F# have pipes, and shells have had them for fifty years. The point is that a web language should have one from the start, because web code is mostly this.

Since then: pipelines and the standard library built for them are in every Quillo program. See Pipelines and method calls.

The Quillo newsletterNew posts, components and plugins, about once a week. No tracking.

Thread
7Useful? Like it, or add to its thread below.

Thread 0 posts

On Reading code left to right: questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.