import { IEnumerable , IEqualityComparer , IGrouping , SelectorKeyType } from "../../types" ; import { BasicEnumerable } from "../BasicEnumerable" ; import { Grouping } from "../Grouping" ; param source param keySelector param comparer private export const groupBy_0 = < TSource , TKey > ( source , keySelector , comparer ) => { return function * generate ( ) { const keyMap = new Array < Grouping < TKey , TSource > > ( ) ; for ( const value of source ) { const key = keySelector ( value ) ; let found = false ; for ( let i = 0 ; i < keyMap . length ; i ++ ) { const group = keyMap [ i ] ; if ( comparer ( group . key , key ) ) { group . push ( value ) ; found = true ; break ; } } if ( found === false ) { keyMap . push ( new Grouping ( key , value ) ) ; } } for ( const keyValue of keyMap ) { yield keyValue ; } } ; } ; private export const groupBy_0_Simple = < TSource , TKey extends SelectorKeyType > ( source , keySelector ) => { return function * iterator ( ) { const keyMap = { } ; for ( const value of source ) { const key = keySelector ( value ) ; const grouping = keyMap [ key ] ; if ( grouping ) { grouping . push ( value ) ; } else { keyMap [ key ] = new Grouping < TKey , TSource > ( key , value ) ; } } for ( const value in keyMap ) { yield keyMap [ value ] ; } } ; } ; private export const groupBy_1_Simple = < TSource , TKey extends SelectorKeyType , TElement > ( source , keySelector , elementSelector ) : IEnumerable < IGrouping < TKey , TElement > > => { function * generate ( ) { const keyMap = { } ; for ( const value of source ) { const key = keySelector ( value ) ; const grouping = keyMap [ key ] ; const element = elementSelector ( value ) ; if ( grouping ) { grouping . push ( element ) ; } else { keyMap [ key ] = new Grouping < TKey , TElement > ( key , element ) ; } } for ( const value in keyMap ) { yield keyMap [ value ] ; } } return new BasicEnumerable ( generate ) ; } ; private export const groupBy_1 = < TSource , TKey , TElement > ( source , keySelector , elementSelector , comparer ) : IEnumerable < IGrouping < TKey , TElement > > => { function * generate ( ) { const keyMap = new Array < Grouping < TKey , TElement > > ( ) ; for ( const value of source ) { const key = keySelector ( value ) ; let found = false ; for ( let i = 0 ; i < keyMap . length ; i ++ ) { const group = keyMap [ i ] ; if ( comparer ( group . key , key ) ) { group . push ( elementSelector ( value ) ) ; found = true ; break ; } } if ( found === false ) { const element = elementSelector ( value ) ; keyMap . push ( new Grouping < TKey , TElement > ( key , element ) ) ; } } for ( const keyValue of keyMap ) { yield keyValue ; } } return new BasicEnumerable ( generate ) ; } ;