3 ms·
function tee(arg) { console.log(arg); return arg; } 2 |> square |> tee |> increment |> square;
by marksomnian 9y ago
function tee(arg) {
console.log(arg);
return arg;
}
2 |> square |> tee |> increment |> square;
- throwanem 9y agoOr even, using another cute toy from the article: const tee = arg => console.log(arg), arg;
- seanwilson 9y agoSo I'm comparing pipe usage to this e.g. const result1 = square(2); const result2 = increment(result1); const result3 = square(result2); With the above, I can add in a breakpoint and inspect what's going on at each stage with access to other debugging tools. Log statements don't seem nearly as good as this. The above is nice as well in that you can give intuitive names to the intermediate results.
- djedr 9y agoIf you need names for intermediate results, etc. then you don't want the pipeline operator/function. In such cases the things you say are true. But when you wan't to be more concise, with the operator/function, you can. BTW A nice feature of a code editor would be if you could magically switch back and forth between code with intermediate named variables and pipelined version of the same code, e.g. by selecting the code and invoking an option.