export default function groupBy(arr: V[], fn: (v: V) => K): Map { const map = new Map(); arr.forEach(e => { const key = fn(e); if (!map.has(key)) { map.set(key, [] as V[]); } map.get(key)!.push(e); }); return map; }