/**
 * Groups array of objects by preferred key
 * @param {Recrod<string, any>[]} arr Array of objects to group
 * @param {String} groupKey Key property to group by
 * @param {Object} [opts]
 * @param {Function} [opts.converter] Convert key to custom delinator
 */
export default function groupToMap(arr, groupKey, {
  converter = d => d,
  objConverter = d => d
} = {}) {
  return arr.reduce((map, obj) => {
    const groupValue = converter(obj[groupKey]);
    if (!map.has(groupValue)) {
      map.set(groupValue, []);
    }
    map.get(groupValue).push(objConverter(obj));
    return map;
  }, new Map());
}