Free debugging

So, we use a very nice ramda library at work, which is great, because we can mainly use the point - free code style. The problem is that there are far fewer places to search when something is wrong, which indicates something in our code; most runtime errors are due to improper use of the ramda's complex functions. Combine this with passing these functions to a framework that uses a lot of redirection (we are in reaction / reduction), and often when something goes wrong, it is deep in the library code, and it is very difficult to know where I went wrong.

Is there a way to mitigate this problem without leaving the dot style?

+4
source share
2 answers

One option is to use R.tap, for example:

const f = R.pipe(
  R.tap(console.log),  // logs x
  g,
  R.tap(console.log),  // logs g(x)
  h,
  R.tap(console.log),  // logs h(g(x))
  i,
  R.tap(console.log),  // logs i(h(g(x)))
  j,
  R.tap(console.log)   // logs j(i(h(g(x))))
);

f(x);

Another option is to use Sanctuary , which leads to informative exceptions when the function is applied to arguments of the wrong types.

+5
source

I encountered the same problem with Ramda in my side projects. This is what made me abandon this in production, for now.

JavaScript . , . unit test , , .

: , Ramda-debug R.tap(), , , . , , , , , .

+3

Source: https://habr.com/ru/post/1659099/


All Articles