UNPKG

ramda.frompairs

Version:

R.fromPairs exported as a module

67 lines (59 loc) 1.89 kB
// Ramda v0.26.1 // https://github.com/ramda/ramda // (c) 2013-2019 Scott Sauyet, Michael Hurley, and David Chambers // Ramda may be freely distributed under the MIT license. (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : (factory((global.R = {}))); }(this, (function (exports) { 'use strict'; function _isPlaceholder(a) { return a != null && typeof a === 'object' && a['@@functional/placeholder'] === true; } /** * Optimized internal one-arity curry function. * * @private * @category Function * @param {Function} fn The function to curry. * @return {Function} The curried function. */ function _curry1(fn) { return function f1(a) { if (arguments.length === 0 || _isPlaceholder(a)) { return f1; } else { return fn.apply(this, arguments); } }; } /** * Creates a new object from a list key-value pairs. If a key appears in * multiple pairs, the rightmost pair is included in the object. * * @func * @memberOf R * @since v0.3.0 * @category List * @sig [[k,v]] -> {k: v} * @param {Array} pairs An array of two-element arrays that will be the keys and values of the output object. * @return {Object} The object made by pairing up `keys` and `values`. * @see R.toPairs, R.pair * @example * * R.fromPairs([['a', 1], ['b', 2], ['c', 3]]); //=> {a: 1, b: 2, c: 3} */ var fromPairs = _curry1(function fromPairs(pairs) { var result = {}; var idx = 0; while (idx < pairs.length) { result[pairs[idx][0]] = pairs[idx][1]; idx += 1; } return result; }); exports.fromPairs = fromPairs; Object.defineProperty(exports, '__esModule', { value: true }); })));