ksa*_*jad 0 javascript functional-programming ramda.js
我在ramda中有一个遗留代码,我很难弄清楚它的作用。如何将ramda函数转换为简单的javascript?我的职能如下:
R.forEach(
R.compose(
vm.importAll,
b =>
R.compose(
R.map(R.merge(R.pick(["index"])(b))),
R.prop("transactions")
)(b)
)
)
Run Code Online (Sandbox Code Playgroud)
代码创建了一个函数,该函数将以下数据结构作为输入-
[ { index: 123
, transactions: [ { ... }, ... ]
}
, { index: 456
, transactions: [ { ... }, ... ]
}
, ...
]
Run Code Online (Sandbox Code Playgroud)
对于输入数组中的每个对象o
,它将构建一个对象事务数组o.transactions
,将对象的索引添加o.index
到每个新的事务对象中。
中间状态如下所示,其中...
表示单个交易数据-
[ { index: 123, ... }, { index: 123, ... }, { index: 123, ... }, ... ]
Run Code Online (Sandbox Code Playgroud)
该数组传递给vm.importAll
,即-
vm.importAll([ { index: 123, ... }, ... ])
Run Code Online (Sandbox Code Playgroud)
对输入数组中的每个对象重复此过程-
vm.importAll([ { index: 456, ... }, ... ])
vm.importAll([ ... ])
Run Code Online (Sandbox Code Playgroud)
享受编写非Ramda版本的乐趣!