function cumulativeTransformSelective (shouldApplyFn) {
  function nominalTsValueToIntervalTsValue(elem, index, arr) {
    if (index === 0) return []
    let prev = arr[index - 1]
    return {
      ...elem, // copy everything over and replace the value with time scaled from previous
      value: ((elem.value - prev.value) / ((elem.ts - prev.ts) / 1000))
    }
  }

  return function _cumulativeTransformSelective (metricInstances) {
    return metricInstances.map(mi => {
      return shouldApplyFn(mi)
        ? { ...mi, data: mi.data.map(nominalTsValueToIntervalTsValue).slice(1) }
        : mi
    })
  }
}
Convert a nominal value to a interval value. Performs a derivative over time.

ie: convert a series that increments forever into an average over the last time period

@param {function} the function that decides whether a cumulative transform should be applied
@returns {function} a transform function