function getKey ( thing ) { return thing . id || thing . name || thing . displayName || thing ; } type KeyFn = typeof getKey ; export class KeyMap < K , V > { private _data = { } ; private _keyFn : KeyFn ; constructor ( keyFn = getKey ) { this . _keyFn = keyFn ; } put ( key , value ) { this . _data [ this . _keyFn ( key ) ] = value ; } get ( key ) { return this . _data [ this . _keyFn ( key ) ] ; } getOrCreate ( key , provider ) { return this . _data [ this . _keyFn ( key ) ] || ( this . _data [ this . _keyFn ( key ) ] = provider ( ) ) ; } containsKey ( key ) { return this . get ( key ) ; } size ( ) { return Object . keys ( this . _data ) . length ; } }