In the team we're trying to decide, if we should use ramda
in our project, or not. The project is on Typesctipt, with React in the front and Nestjs in the back.
Currently the lists of pros and cons look like this
Pros:
- The code is easy to read
- The pure functions are easy to test and to refactor
Cons:
- Difficult to read, if you are new to ramda
- Ramda has problems with types, e.g.
interface Obj {p1: {p2: number}}
const obj: Obj = {
p1: {
p2: 1,
}
}
const value = pathOr(null, ['p1', 'p2'], obj); //type of "value" will be "any"
- Using
ramda
with classes looks awkward, e.g.
class Cl {
method1() {...}
method2() {...}
method3() {
return compose(
this.method1.bind(this),
this.method2.bind(this),
)()
}
}
Will be glad to see any considerations on these points, or more pros and cons to add. Thanks.
Updated:
Taking into account geoffrey's comment, when it's impossible not to use classes (like in NestJS), it's probably better to split fp-style functions from class methods, because they are pure functions anyway:
const method1Fn = () => {...};
const method2Fn = () => {...};
const method3Fn = () => compose(
method1Fn,
method2Fn,
)
class Cl {
method3() {
return method3Fn()
}
}
or even
class Cl {
method3 = method3Fn
}
but in this case method3 will be created for every instance of Cl
.