function validateAndSetDefaultStatesConfigurator(
  fieldChain,
  validateFuncs,
  setDefaultFuncs
) {
  return state => {
    return fieldChain.reduce((acc, field) => {
      const validateFunc = validateFuncs[field];
      const setDefaultFunc = setDefaultFuncs[field];
      assert(
        typeof validateFunc === 'function' &&
          typeof setDefaultFunc === 'function',
        `both validateFuncs[${field}] and setDefaultFuncs[${field}] need to be functions`
      );
      return validateAndSetDefaultStateSingle(
        acc,
        field,
        validateFunc,
        setDefaultFunc
      );
    }, state);
  };
}
Used for configuring 1) validation criteria for each field in state;
2) default value fro each state if they are invalid; 3) dependency chain among fields
@param {Array<String>} fieldChain - an array of field names in `state`.
Order if the fields dignify the dependency relationship between fields:
default values of fields with a larger index might depend on (zero or more) fields with a smaller index
fields with a larger index never depend on fields with smaller indices
@param {Map<String:Function>} validateFuncs - a mapping from each of the field names to functions to check whether those fields are valid
@param {Map<String:Function>} setDefaultFuncs - a mapping from each of the field names to functions that returns default value of that field
@return {Function} a function to validate each of the fields in state on-by-one, and set them to default if they are invalid. Input: state; output: updated state

@example
const state = {a: 2, b: 2, c: 2};
const validateFuncs = {
  b: state => state.b > state.a,
  c: state => state.c > state.b,
};
const setDefaultFuncs = {
  b: state => state.a + 1,
  c: state => state.b + 2,
};
const validateAndSetDefault = validateAndSetDefaultStatesConfigurator(['b', 'c'], validateFuncs, setDefaultFuncs);
const validateAndSetDefaultReversed = validateAndSetDefaultStatesConfigurator(['c', 'b'], validateFuncs, setDefaultFuncs);
validateAndSetDefault(state);
// returns {a: 2, b: 3, c: 5}
validateAndSetDefaultReversed(state);
// returns {a: 2, b: 3, c: 4}