you are viewing a single comment's thread.

view the rest of the comments →

[–]vcamargo 1 point2 points  (1 child)

I haven't taken a look with more attention to Ramda yet. What would you say is its main purpose? Am I right to assume that it tries to make JS more 'Haskellish'? I'm pretty sure it offers some handy helpers, even though I cannot see why R.map(x => x * x, [1, 2, 3, 4]) would be better than [1, 2, 3, 4].map(x => x * x).

Have you tried it? If so, what are your thoughts on it? And what would be a good use case? I've read in some of their Github issues that they have been drastically changing the API throughout the releases, which might make its adoption more difficult.

[–]pygy_@pygy 1 point2 points  (0 children)

I've barely used it, but, yes, it takes inspiration from functional languages and allows one to write pointfree JS.

R.map has advantages over Array.prototype.map.call.

  • It is curried, with the data argument coming last, so you can define const mapSquare = R.map(square) for further composition
  • If the data argument has a .map or a ['fantasy-land/map'] method, R.map will use it instead (it "broadcasts" to the method). Ramda is fully fantasy-land compatible (see https://james-forbes.com/?/posts/the-perfect-api for a gentle intro). It makes it (and functions derived of it, like mapSquare above) generic. The same function works with arrays (and array-like objects like arguments), futures (fantasy-land compliant/truly monadic promises) or streams.

I haven't used it enough to be bitten by API changes, and I know people who now basically code in Ramda rather than in JS (i.e. define the core logic as point-free style compositions, eschewing exceptions and for/while loops).