import { BotLookupTable , valuesToKey , buildLookupTable , } from './BotLookupTable' ; import { Bot } from './Bot' ; import { BotObjectsContext } from './BotObjectsContext' ; import { zip , sortBy } from 'lodash' ; /**
 * Defines a helper class for BotLookupTable which is able to dynamically create and reuse
 * lookup tables for a calculation context.
 */ export class BotLookupTableHelper { private _tables : Map < string , BotLookupTable > ; constructor ( ) { this . _tables = new Map ( ) ; } param calc param tags param values param defaulst query ( calc , tags , values , defaults ? ) { const zipped = zip ( tags , values ) ; const sorted = sortBy ( zipped , ( z ) => z [ 0 ] ) ; const sortedTags = sorted . map ( ( s ) => s [ 0 ] ) ; const sortedValues = sorted . map ( ( s ) => s [ 1 ] ) ; let key = valuesToKey ( sortedTags ) ; let table = this . _tables . get ( key ) ; if ( ! table ) { table = buildLookupTable ( calc , sortedTags , defaults ) ; this . _tables . set ( key , table ) ; } return table . query ( sortedValues ) ; } }