export class DefaultMap < K , V > extends Map < K , V > { defaultFn : ( key : K ) => V ; constructor ( defaultFn , iterable ? ) { if ( iterable ) { super ( iterable ) ; } else { super ( ) ; } this . defaultFn = defaultFn ; } get ( key ) { let val = super . get ( key ) ; if ( val === undefined ) { val = this . defaultFn ( key ) ; super . set ( key , val ) ; } return val ; } }