import { GroupBy } from './types' ; import { List } from '../types' ; import { curry2 } from '@typed/functions' ; name export const groupBy = curry2 ( __groupBy ) ; function __groupBy < Keys extends string , A > ( f , list ) { const itemCount = list . length ; const strMap = { } as Record < Keys , Array < A > > ; for ( let i = 0 ; i < itemCount ; ++ i ) { const value = list [ i ] ; const key = f ( value ) ; if ( strMap [ key ] ) strMap [ key ] . push ( value ) ; else strMap [ key ] = [ value ] ; } return strMap ; }