Hey,
recently I wrote some function pipelines and wanted to debug the output. Example:
props.value
->Array.filter(item => item.id !== id)
->Array.map(item => item.id)
->Array.join(",")
->props.onChange
Since I didn’t save the result in a variable and just wanted to print it to the console, I had two options:
- copy the whole block, replace in the first pipeline the last
props.onChangewithconsole.log - remove the last
props.onChange, save the result in a variable, callconsole.logandprops.onChangeseparately.
Cumbersome.
What do you think about a Console.log, which prints the value and returns it?
(I found out that gleam lang introduced an echo function for the same purpose, so I chose the same name).
props.value
->Array.filter(item => item.id !== id)
->echo
->Array.map(item => item.id)
->echo
->Array.join(",")
->echo
->props.onChange
Could be a handy function in the @rescript/core library.
Console.echo, top level echo, Debug.logAndReturn, Console.logAndReturn…
(if using something like logAndReturn we could also implement infoAndReturn, debugAndReturn etc.).
If you agree with me, I’m open to create a PR for this.
Cheers,
Daniel