Yes, it's just map
.
map
operates on any Functor , and Ramda supplies the implementations for arrays, objects, and functions, all of which are functors, and delegates to map
methods for other types.
So you can just use 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>
I think mapObjIndexed
could do the similar things as mapValues
but without the iteratee shorthands.
const users = {
fred: { user: 'fred', age: 40 },
pebbles: { user: 'pebbles', age: 1 }
};
R.mapObjIndexed((value, key) => value.age, users)
which outputs:
{"fred": 40, "pebbles": 1}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.