fromPairs

Constructs an object from an array of (key, value) pairs.

Signature

fromPairs(pairs)
(Array (String or Symbol, 'a)) => Object 'a

Documentation

Constructs an object from an array of (key, value) pairs.

The resulting object is a plain JavaScript object, inheriting from Object.prototype.

The pairs are added to the object with Object.defineProperty, so no setters defined in Object.prototype will be triggered during the process. All properties are enumerable, writable, and configurable.

Example:

const fromPairs = require('folktale/core/object/from-pairs');

fromPairs([['x', 10], ['y', 20]]);
// ==> { x: 10, y: 20 }

Caveats

Properties are inserted in the object in the same order of the array. In an ECMAScript 2015-compliant engine this means that the following equivalence holds:

const fromPairs = require('folktale/core/object/from-pairs');

Object.keys(fromPairs(xs)) === xs.map(([k, v]) => k)

However, in engines that don't conform to ECMAScript 2015, this equivalence is not guaranteed.

Properties

Source Code

Defined in source/core/object/from-pairs.js at line 22, column 0
(pairs) =>
        pairs.reduce((r, [k, v]) => define(r, k, { value: v,
                                                   writable: true,
                                                   enumerable: true,
                                                   configurable: true
                                                  }),
                     {})
Stability
stable
Licence
MIT
Module
folktale/core/object/from-pairs
Authors
Copyright
(c) 2013-2017 Quildreen Motta, and CONTRIBUTORS
Authors
  • Quildreen Motta
Maintainers
  • Quildreen Motta <queen@robotlolita.me> (http://robotlolita.me/)