3 ms·
Is there a good way to see the intermediate results at each stage in the pipe when things go wrong? Pipes are concise but perhaps harder to debug depending on w
by seanwilson 9y ago
Is there a good way to see the intermediate results at each stage in the pipe when things go wrong? Pipes are concise but perhaps harder to debug depending on what tools you have.
- marksomnian 9y agofunction 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.
- deleted 9y ago[deleted]
- djedr 9y agoYou can define a debug version: const pipe_debug = (...args) => args.reduce((prev, curr) => { console.log('pipe debug; curr:', curr, ', prev:', prev) return curr(prev) }) and when you want to see intermediate results of a `pipe` call, you append `_debug` to the name.