How to use the mapObjIndexed function from ramda

Find comprehensive JavaScript ramda.mapObjIndexed code examples handpicked from public code repositorys.

ramda.mapObjIndexed is a function in Ramda library that iterates over an object properties and maps them into a new object, while providing the key as a second argument to the iteratee.

160
161
162
163
164
165
166
167
168
169
  R.uniq,
  R.filter(R.propEq("color", color)),
  R.map(getTile)
)(R.keys(game.tiles));

R.mapObjIndexed((dups, id) => {
  let tile = getTile(id);
  if (tile.color !== color) return;

  // Merge tile with game tile
fork icon52
star icon51
watch icon0

162
163
164
165
166
167
168
169
170
171
172
    throw new Error(`${network} deployment not supported`)
  }
}


const accounts = accountsMetadata(chainId)
const names = R.mapObjIndexed((item) => item.account, accounts)
const allContracts = []
const allContractNames = []
const allAccounts = []
const allBankAccountNames = []
fork icon1
star icon0
watch icon6

+ 2 other calls in file

How does ramda.mapObjIndexed work?

ramda.mapObjIndexed is a higher-order function provided by the Ramda library that takes a function and a plain JavaScript object as input and returns a new object where the function is applied to each property value and the property name is passed as a second argument to the function.

288
289
290
291
292
293
294
295
296
297
key: "merge",
value: function merge(prevCatalogs, nextCatalog, options) {
  var _this = this;

  var nextKeys = R.keys(nextCatalog).map(String);
  return R.mapObjIndexed(function (prevCatalog, locale) {
    var prevKeys = R.keys(prevCatalog).map(String);
    var newKeys = R.difference(nextKeys, prevKeys);
    var mergeKeys = R.intersection(nextKeys, prevKeys);
    var obsoleteKeys = R.difference(prevKeys, nextKeys); // Initialize new catalog with new keys
fork icon1
star icon0
watch icon0

+ 5 other calls in file

44
45
46
47
48
49
50
51
52
53
  return console.log(error);
}
var data = JSON.parse(body);
var notes
  = R.compose(
      R.mapObjIndexed((v, k, o) => R.sortWith([R.ascend(R.prop('date'))], v)),
      R.groupBy(o => o.source),
      R.map(o => ({
        date: new Date(o.updated),
        title: o.document.title,
fork icon0
star icon6
watch icon0

Ai Example

1
2
3
4
const obj = { a: 1, b: 2, c: 3 };
const addIndex = (val, key) => `${val}_${key}`;
const result = R.mapObjIndexed(addIndex, obj);
console.log(result); // { a: '1_a', b: '2_b', c: '3_c' }

In this example, mapObjIndexed is used to create a new object by iterating over the properties of an existing object and applying a function to each property's value and key. The resulting object has the same keys as the original object, but with the corresponding values transformed by the given function.

99
100
101
102
103
104
105
106
107

db.on("error", err => {
  error("idle client error: %s %j", err.message, err.stack);
});

const renderedQueries = R.mapObjIndexed(
  query => mustache.render(query, context, queries),
  queries
);
fork icon0
star icon2
watch icon0

134
135
136
137
138
139
140
141
142
143
exports.generate = function generate(source, transformers = []) {
  if (source === null || source === undefined) {
    return {}; // For motion.ant.design, it doesn't need source sometimes.
  }
  if (R.is(Object, source) && !Array.isArray(source)) {
    return R.mapObjIndexed(value => generate(value, transformers), source);
  }
  const sources = ensureToBeArray(source);
  const validFiles = findValidFiles(sources, transformers);
  const filesTree = filesToTreeStructure(validFiles, sources);
fork icon0
star icon0
watch icon1

+ 2 other calls in file

6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
 * @example
 *
 *      var values = { x: 1, y: 2, z: 3 };
 *      var prependKeyAndDouble = (num, key, obj) => key + (num * 2);
 *
 *      R.mapObjIndexed(prependKeyAndDouble, values); //=> { x: 'x2', y: 'y4', z: 'z6' }
 */
var mapObjIndexed = _curry2(function mapObjIndexed(fn, obj) {
    return _reduce(function (acc, key) {
        acc[key] = fn(obj[key], key, obj);
fork icon0
star icon0
watch icon0

+ 17 other calls in file

9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
 * @example
 *
 *      const xyz = { x: 1, y: 2, z: 3 };
 *      const prependKeyAndDouble = (num, key, obj) => key + (num * 2);
 *
 *      R.mapObjIndexed(prependKeyAndDouble, xyz); //=> { x: 'x2', y: 'y4', z: 'z6' }
 */




var mapObjIndexed =
fork icon0
star icon0
watch icon2

+ 3 other calls in file

21
22
23
24
25
26
27
28
29
30
31
32
33


  process.env.BABEL_ENV = env
  process.env.NODE_ENV = env
}


const stringifyValues = r.mapObjIndexed(JSON.stringify)


function ensureSlash(path, needsSlash) {
  const pathWithoutLastSlash = removeLastSlash(path)

fork icon0
star icon0
watch icon0

70
71
72
73
74
75
76
77
78
79
80
module.exports.send = async (details) => {
    logInfo('Request to send sms and whatsapp notifications', details);


    const NotificationConfig = messagesRepository.get(details.preferredLanguage);
    const notificationDetails = Object.assign({}, NotificationConfig[details.context]);
    const messages = R.mapObjIndexed((num, key, obj) => R.cond([
        [isFcm, () => getFCMMessage(details.data, notificationDetails.messages[key])],
        [isEmail, () => getEmailMessage(details.data, notificationDetails.messages[key])],
        [isSms, () => getGenericMessage(details.data, notificationDetails.messages[key])],
        [isWhatsApp, () => getGenericMessage(details.data, notificationDetails.messages[key])],
fork icon0
star icon0
watch icon0

12
13
14
15
16
17
18
19
20
21
const now = new Date()
const event = github.context.payload.pull_request
const picks = r.paths(airtablePicks, event)

const paths = r.map(p => p.join('.'), airtablePicks)
const payload = r.mapObjIndexed((_,key, obj)=> {
  let p = airtableTraversal[key]
  if(p) return obj[key].map(r.path(p))
  else return obj[key]
})(r.zipObj(paths, picks))
fork icon0
star icon0
watch icon0

27
28
29
30
31
32
33
34
35
36
req.logger.child({ services }),
'getServicePublicKeys',
() => R.compose(
  maybeFilterByServices,
  R.values,
  R.mapObjIndexed((keys, serviceName) => ({
    serviceName,
    currentPublicKey  : keys[0],
    previousPublicKey : keys[1]
  })),
fork icon0
star icon0
watch icon0

Other functions in ramda

Sorted by popularity

function icon

ramda.clone is the most popular function in ramda (30311 examples)