【发布时间】:2023-03-29 19:43:01
【问题描述】:
在 javascript 和 typescript 中使用函数式编程以及 Ramda,我经常发现自己编写如下代码:
const myFun = c => {
const myId = c.id
const value = pipe(
getAnotherOtherPropOfC,
transformToArray,
mapToSomething,
filterSomething,
// ... N other transformations
// ok now I need myId and also the result of the previous function
chainMyIdWithResultOfPreviousFunction(myId)
)(c)
return value
}
注意创建const myId 如何打破无点样式。我想写myFun 这样就不需要明确的c。所以像:
const myFun = pipe(....)
我想知道是否有更实用和更易读的方式来做这样的事情。
【问题讨论】:
-
多次使用变量非常在没有无点样式的情况下更容易和可读。
-
第二个输入有什么问题吗? IE。
const myFun = (c, id) => {...}
标签: javascript functional-programming ramda.js