selfrefactor / rambda

Faster and smaller alternative to Ramda
https://selfrefactor.github.io/rambda
MIT License
1.65k stars 89 forks source link

[Feature] Allow Different Ouput Types for Set, Over, Etc #740

Closed TheMayoras closed 2 months ago

TheMayoras commented 2 months ago

I may be using this library wrong, but I've come run into a type limitation that feels like it should be possible. I'd like to be able to use R.over, R.set, etc with a different output type.

One line example: R.over(R.lensProp('x'), (n: number) => n.toString(), {x: 1}).

I ran into this issue because I need to convert a single field of a fetch's response to a new type. I got around the issue by using R.assoc, but it didn't feel like an FP way to solve the problem.

const obj = {x: "1"};
R.assoc(
      "x",
      parseInt(obj.x),
      obj
    );
selfrefactor commented 2 months ago

The thing is that with Ramda, your example again leads to error. Rambda typings try to match Ramda typings where possible. It seems that it is indeed required fn input in over to keep the same type, i.e. no transformation.

selfrefactor commented 2 months ago

I am closing the issue, but feel free to comment further.