Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 2592

Console.log with return value

$
0
0

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:

  1. copy the whole block, replace in the first pipeline the last props.onChange with console.log
  2. remove the last props.onChange, save the result in a variable, call console.log and props.onChange separately.

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


Viewing all articles
Browse latest Browse all 2592

Trending Articles