[英]Is there any function equivalent to mapValues in ramda.js (similar to lodash)?
是的,它只是map
。
map
在任何Functor map
运行,Ramda提供数组,对象和函数的实现,它们都是函子,并为其他类型的map
方法提供委托。
所以你可以只使用map
:
const square = n => n * n console .log ( map (square, {a: 1, b: 2, c: 3}) //=> {a: 1, b: 4, c: 9} ) console .log ( map (toUpper, {x: 'foo', y: 'bar'}) //=> {x: 'FOO', y: 'BAR'} )
<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.26.1/ramda.js"></script><script> const {map, toUpper} = R </script>
我认为mapObjIndexed
可以做与mapValues
类似的事情,但是没有iteratee的简写形式。
const users = {
fred: { user: 'fred', age: 40 },
pebbles: { user: 'pebbles', age: 1 }
};
R.mapObjIndexed((value, key) => value.age, users)
输出:
{"fred": 40, "pebbles": 1}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.