/** @module pairs/fromPairs.ts */ import { Pairs } from '../helper-types' import { assoc_ } from '../object' /** * Converts an array of entry pairs into an obj * @param entries array of pairs * @example * fromPairs([ ['a',1 ], ['b', 2]]) * // => {a:1, b: 2} */ export const fromPairs = ( entries: Pairs ): Record => entries.reduce( ( acc, [ k, v ] ) => assoc_( k as string, v, acc ), {} ) // interface KeyValuePair extends Array { // 0: K // 1: V // } // const _fromPairs = untypedCurry( ( kv: Array> ) => // kv.reduce( // ( acc, [ k, v ] ) => assign( acc, {[ k ]: v} ) , // {}, // ), // ) // export function fromPairs ( kv: Array> ): { [index: string]: V } // export function fromPairs ( kv: Array> ): { [index: number]: V } // export function fromPairs( ...args ) { // return _fromPairs( ...args ) // } export default fromPairs