import { CalculationCache } from "./interfaces" ; param export let createCache = < Result > ( ) : CalculationCache < Result > => { let cachedInputs ; let cachedOutcome ; return { invalidate : ( ) => { cachedOutcome = undefined ; cachedInputs = undefined ; } , result : ( inputs , calculation ) => { if ( cachedInputs ) { for ( let i = 0 ; i < inputs . length ; i ++ ) { if ( cachedInputs [ i ] !== inputs [ i ] ) { cachedOutcome = undefined ; } } } if ( ! cachedOutcome ) { cachedOutcome = calculation ( ) ; cachedInputs = inputs ; } return cachedOutcome ; } , } ; } ;