mapValues

Transforms values of an object with an unary function.

Signature

mapValues(object, transformation)
(Object 'a, ('a) => 'b) => Object 'b

Documentation

Transforms values of an object with an unary function.

The transformation works on the values of each own, enumerable property of the given object. Inherited and non-enumerable properties are ignored by this function.

Example:

const mapValues = require('folktale/core/object/map-values');

const pair = { x: 10, y: 20 };
mapValues(pair, x => x * 2);
// ==> { x: 20, y: 40 }

Caveats

mapValues will not preserve the shape of the original object. It treats objects as plain maps from String to some value, and ignores things like prototypical delegation, symbols, and non-enumerable properties.

Properties

Convenience

infix(transformation)

Conveniently transforms values in an object using the This-Binding syntax.

Source Code

Defined in source/core/object/map-values.js at line 19, column 0
(object, transformation) => {
  const keys = Object.keys(object);
  const result = {};

  for (let i = 0; i < keys.length; ++i) {
    const key = keys[i];
    result[key] = transformation(object[key]);
  }

  return result;
}
Stability
stable
Licence
MIT
Module
folktale/core/object/map-values
Authors
Copyright
(c) 2013-2017 Quildreen Motta, and CONTRIBUTORS
Authors
  • Quildreen Motta
Maintainers
  • Quildreen Motta <queen@robotlolita.me> (http://robotlolita.me/)