import * as assert from "@esfx/internal-assert" ; import { HashMap } from '@esfx/collections-hashmap' ; import { Equaler } from '@esfx/equatable' ; import { Grouping } from '@esfx/iter-grouping' ; class LookupIterable < K , V , R > implements Iterable < R > { private _map : ReadonlyMap < K , Iterable < V > > ; private _selector : ( key : K , elements : Iterable < V > ) => R ; constructor ( map , selector ) { this . _map = map ; this . _selector = selector ; } * [ Symbol . iterator ] ( ) { const map = this . _map ; const selector = this . _selector ; for ( const [ key , values ] of map ) { yield selector ( key , values ) ; } } } export class Lookup < K , V > implements Iterable < Grouping < K , V > > { private _entries : HashMap < K , Iterable < V > > ; private _source : Iterable < Grouping < K , V > > ; param entries constructor ( entries , keyEqualer ? ) { assert . mustBeIterableObject ( entries , "entries" ) ; assert . mustBeTypeOrUndefined ( Equaler . hasInstance , keyEqualer , "keyEqualer" ) ; this . _entries = new HashMap ( entries , keyEqualer ) ; this . _source = new LookupIterable < K , V , Grouping < K , V > > ( this . _entries , Grouping . from ) ; } /**
     * Gets the number of unique keys.
     */ get size ( ) : number { return this . _entries . size ; } param key has ( key ) { return this . _entries . has ( key ) ; } param key get ( key ) { return this . _entries . get ( key ) || [ ] ; } param selector applyResultSelector < R > ( selector ) { assert . mustBeFunction ( selector , "selector" ) ; return new LookupIterable ( this . _entries , selector ) ; } [ Symbol . iterator ] ( ) { return this . _source [ Symbol . iterator ] ( ) ; } }