March 2019
Intermediate to advanced
208 pages
5h 11m
English
The preceding code works fine, but it’s a bit clunky. Each stage of the calculation is stored in a new variable binding that is used in the next stage. Wouldn’t it be nice if we could pass the result of each calculation to the next one without all those variables? We can do exactly that with ->, the pipe first operator.
Pipe first says: “take the value to the left of the -> and pipe it to the function on the right.” (In older code, you may see |. used as the pipe first operator. You may also see it referred to by its former name: fast pipe.)
We’ll put the final switch into a function, allowing us to do this:
| | let makeDisplayText = (s: option(string)): string => { |
| | switch ( ... |
Read now
Unlock full access