jstaab jstaab - 1 year ago 116
Javascript Question

Point free debugging

So we're using the very nice ramda library at work, which is great because we're able to use a largely point-free style of code. The problem with this is that there are far fewer places to look when things go wrong that point to something in our code; most run time errors occur because of a misuse of composed ramda functions. Combine this with passing these functions to a framework that uses a lot of redirection (we're on react/redux), and often when something goes wrong, it's deep in library-only code, and it's very hard to find out where I went wrong.

Is there any way to mitigate this problem without moving away from point-free style?

Answer Source

One option is to use R.tap, like so:

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


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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download