module/src/utils.js
/**
 * Reduce and map a given sequence of items to a map.
 * @param  {toMap~selector} keySelector - the selector that will be called to establish the key of a given item within the sequence
 * @param  {toMap~selector} valueSelector - the selector that will be called to establish the value of a given item within the sequence
 * @return {Map}
 */
Reduce and map a given sequence of items to a map.
@param  {toMap~selector} keySelector - the selector that will be called to establish the key of a given item within the sequence
@param  {toMap~selector} valueSelector - the selector that will be called to establish the value of a given item within the sequence
@return {Map}
Reduce and map a given sequence of items to a map . @param { toMap~selector } keySelector - the selector that will be called to establish the key of a given item within the sequence @param { toMap~selector } valueSelector - the selector that will be called to establish the value of a given item within the sequence @return { Map }
function toMap(keySelector, valueSelector) {
    const items = [...this];
    if (typeof keySelector !== 'function') {
        throw new TypeError(`Parameter 'keySelector' must be a function.`);
    }
    if (typeof valueSelector !== 'function') {
        throw new TypeError(`Parameter 'valueSelector' must be a function.`);
    }
    const map = new Map();
    const reduction = items.reduce((map, item, i) => {
        const key = keySelector(item, i);
        const value = valueSelector(item, i)
        map.set(key, value);
        return map;
    }, map);
    return reduction;
}
function toMap ( keySelector , valueSelector ) { const items = [ ... this ] ; if ( typeof keySelector !== 'function' ) { throw new TypeError ( ` ` ) ; } if ( typeof valueSelector !== 'function' ) { throw new TypeError ( ` ` ) ; } const map = new Map ( ) ; const reduction = items . reduce ( ( map , item , i ) => { const key = keySelector ( item , i ) ; const value = valueSelector ( item , i ) map . set ( key , value ) ; return map ; } , map ) ; return reduction ; }
Reduce and map a given sequence of items to a map.
Reduce and map a given sequence of items to a map .