<commit_before>export const createActionCreator = (type, ...argNames) =>
  (...args) => {
    const action = { type, payload: {} };
    argNames.forEach((arg, index) => {
      action.payload[argNames[index]] = args[index];
    });

    return action;
  };

export const createAPIActionTypes = ({ namespace = '', type }) => {
  const prefix = `${namespace ? `${namespace}/` : ''}${type.toUpperCase()}`;

  return [
    `${prefix}_REQUEST`,
    `${prefix}_SUCCESS`,
    `${prefix}_FAILURE`,
    `${prefix}_RESET`,
  ];
};

export const createReducer = (initialState, handlers) =>
  (state = initialState, action) => {
    if (handlers[action.type]) {
      return handlers[action.type](state, action);
    }

    return state;
  };

export const createReducerForAction = (actionType, initialState) =>
  (state = initialState, action) => {
    if (action.type === actionType) {
      return action.payload;
    }

    return state;
  };

const hasValidTypes = types =>
  Array.isArray(types) &&
  types.length === 4 &&
  types.every(type => typeof type === 'string');

export const createAPIReducerHandlers = types => {
  if (!hasValidTypes(types)) {
    throw new Error('Expected an array of three string types.');
  }

  return {
    // request
    [types[0]]: state => ({
      ...state,
      isFetching: true,
      error: null,
      response: null,
    }),

    // success
    [types[1]]: (state, { payload }) => ({
      ...state,
      isFetching: false,
      response: payload,
      error: null,
    }),

    // failure
    [types[2]]: (state, { error }) => ({
      ...state,
      isFetching: false,
      error,
    }),

    // reset
    [types[3]]: () => ({
      isFetching: false,
      error: null,
      response: null,
    }),
  };
};

export const createAPIReducer = (initialState = {}, types) =>
  createReducer(
    {
      isFetching: false,
      error: null,
      response: null,
      ...initialState,
    },<commit_msg>improving readability<commit_after>export const createActionCreator = (type, ...argNames) =>
  (...args) => {
    const action = { type, payload: {} };
    argNames.forEach((arg, index) => {
      action.payload[argNames[index]] = args[index];
    });

    return action;
  };

export const createAPIActionTypes = ({ namespace = '', type }) => {
  const prefix = `${namespace ? `${namespace}/` : ''}${type.toUpperCase()}`;

  return [
    `${prefix}_REQUEST`,
    `${prefix}_SUCCESS`,
    `${prefix}_FAILURE`,
    `${prefix}_RESET`,
  ];
};

export const createReducer = (initialState, handlers) =>
  (state = initialState, action) => {
    if (handlers[action.type]) {
      return handlers[action.type](state, action);
    }

    return state;
  };

export const createReducerForAction = (actionType, initialState) =>
  (state = initialState, action) => {
    if (action.type === actionType) {
      return action.payload;
    }

    return state;
  };

const hasValidTypes = types =>
  Array.isArray(types) &&
  types.length === 4 &&
  types.every(type => typeof type === 'string');

export const createAPIReducerHandlers = types => {
  if (!hasValidTypes(types)) {
    throw new Error('Expected an array of three string types.');
  }

  const [REQUEST, SUCCESS, FAILURE, RESET] = types;

  return {
    [REQUEST]: state => ({
      ...state,
      isFetching: true,
      error: null,
      response: null,
    }),

    [SUCCESS]: (state, { payload }) => ({
      ...state,
      isFetching: false,
      response: payload,
      error: null,
    }),

    [FAILURE]: (state, { error }) => ({
      ...state,
      isFetching: false,
      error,
    }),

    [RESET]: () => ({
      isFetching: false,
      error: null,
      response: null,
    }),
  };
};

export const createAPIReducer = (initialState = {}, types) =>
  createReducer(
    {
      isFetching: false,
      error: null,
      response: null,
      ...initialState,
    },
{'fraction_non_alphanumeric': 0.17347725520431764, 'fraction_numerical': 0.0015420200462606013, 'mean_word_length': 2.6103896103896105, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4216971', 'n_tokens_mistral': 1227, 'n_tokens_neox': 1228, 'n_words': 277}