您的位置:首页 > 其它

[Ramda] Getter and Setter in Ramda & lens

2016-10-10 21:12 381 查看
Getter on Object:

1. prop:

R.prop('x', {x: 100}); //=> 100
R.prop('x', {}); //=> undefined


2. props:

R.props(['x', 'y'], {x: 1, y: 2}); //=> [1, 2]
R.props(['c', 'a', 'b'], {b: 2, a: 1}); //=> [undefined, 1, 2]


Setter ob Object:

R.assoc('c', 3, {a: 1, b: 2}); //=> {a: 1, b: 2, c: 3}


Another way to use Lens:

var xLens = R.lens(R.prop('x'), R.assoc('x'));

R.view(xLens, {x: 1, y: 2});            //=> 1
R.set(xLens, 4, {x: 1, y: 2});          //=> {x: 4, y: 2}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐