Search code examples
javascriptdebuggingpointfreeramda.js

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?


Solution

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

    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 raises informative exceptions when a function is applied to arguments of the wrong types.