Step by step with the pipe
Hand a value from step to step with |>, where % is what the step
before gave, so a calculation reads in the order it runs.
After reading this page, you will be able to write a calculation as steps that read in the order they run, use
% for the value a step is given, pipe into a match, and read what the parser says about a pipe it cannot take.The pipe is TC39's pipe proposal, its Hack form, with
% as the topic. Ljós adds no syntax of its own: a script is TypeScript, and a pipe is compiled away into plain TypeScript before anything else reads it.head |> body works out head, then gives the value of body, where % in the body is what the head gave. A chain hands each value on: a |> f(%) |> g(%) is g(f(a)), written in the order it runs.A discount, kept at zero or more, as a share of the old price, rounded:
Written inside out, the same binding is
Math.round(Math.max(oldPrice - newPrice, 0) / oldPrice * 100), and its first step is the last thing you read.A step is any expression that uses
%: a call, a method, an operator, a template, an array. The head is worked out once, however many times the step reads %.In
% % 3, the first % is the topic and the second is the remainder: where an operand goes, % is the topic; between two operands, it is the operator it always was.A step that is an arrow function, a conditional, an assignment or a
yield is written in parentheses, so it cannot be read as part of the pipe around it:A pipe inside a step has its own
% for its own steps; its head reads the outer one. A function inside a step that reads % keeps the value it saw.nested is 43: the inner pipe gives (3 + 1) * 10, and the outer % is still 3.A pipe hands a
match its subject, and the arms read % (see Pattern matching). How long ago an article came out, in minutes, chosen among guards:The translated strings carry their number as
%1, so a translator can put it where the language wants it.A step may
await, in an async function, and the steps still run in order:A pipe goes in the scripts of a QML file of Ljós's own API (bindings, handlers and functions), and in an
.lts module. A .ts module stays plain TypeScript, so that stock TypeScript tools read it as they read any other; a pipe in one is the error ts-lts-syntax, and ljos migrate --write renames the file to .lts and rewrites every import that names it:The checker types
% as the head and each step as its body, so a mistake is reported where it is made:The proposal's rules are errors that say so:
The proposal's possible future additions, such as
|>>, |?> and +>, are not in it.










