gpt4 book ai didi

javascript - Pointfree 在 Ramda 中通过对象中的键将数组连接到字符串

转载 作者:行者123 更新时间:2023-11-29 15:27:54 24 4
gpt4 key购买 nike

可以this完成 pointfree 了吗?

var joinByKey = R.curry(function(key, model){
return R.assoc(key, R.join(',' ,R.prop(key, model)), model);
});

var input = { a: ['1', '2', '3'] };
var result = joinByKey("a", input); // {"a": "1,2,3"}

最佳答案

是的,可以这样做:

const joinByKey = key => R.over(
R.lensProp(key),
R.join(',')
);

const input = { a: ['1', '2', '3'] };
const result = joinByKey("a")(input); // {"a": "1,2,3"}

如果你想直接使用它:

const joinByKey = R.curry((key, model) => R.over(
R.lensProp(key),
R.join(',')
)(model));

var input = { a: ['1', '2', '3'] };
joinByKey("a", input); // {"a": "1,2,3"}

第二个既适用于 currified 也适用于非 currified。

我发现它比你的版本更具可读性,与@naomik 所说的相反...

关于javascript - Pointfree 在 Ramda 中通过对象中的键将数组连接到字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37480319/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com