繁体   English   中英

PointFree通过对象中的键,在Ramda中将Array连接到String

[英]Pointfree Join Array to String, by key in object, in Ramda

可以点免费吗?

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"}

第二个工作既可以使用也可以不进行验证。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM