<commit_before>import identity from 'lodash/identity'
import isFunction from 'lodash/isFunction'
import invariant from 'invariant'
import isNull from 'lodash/isNull'

function flat (key, payloadCreator = identity) {
  invariant(
    isFunction(payloadCreator) || isNull(payloadCreator),
    'Expected payloadCreator to be a function, undefined or null'
  )
  return function (...params) {
    return { [key]: payloadCreator(...params) }
  }
}

// port from redux
function compose (...funcs) {
  if (funcs.length === 0) return arg => arg
  if (funcs.length === 1) return funcs[0]
  return funcs.reduce((a, b) => (...args) => a(b(...args)))
}

export default function nest (...keys) {
  const nestFuncs = keys.map(
    (key) => (updateFunction) => flat(key, updateFunction)
  )
  return compose(...nestFuncs)
}
<commit_msg>refactor: rename wrap -> wrapPayloadCreator<commit_after>import identity from 'lodash/identity'
import isFunction from 'lodash/isFunction'
import invariant from 'invariant'
import isNull from 'lodash/isNull'

function wrapPayloadCreator (key, payloadCreator = identity) {
  invariant(
    isFunction(payloadCreator) || isNull(payloadCreator),
    'Expected payloadCreator to be a function, undefined or null'
  )
  return function (...params) {
    return { [key]: payloadCreator(...params) }
  }
}

// port from redux
function compose (...funcs) {
  if (funcs.length === 0) return arg => arg
  if (funcs.length === 1) return funcs[0]
  return funcs.reduce((a, b) => (...args) => a(b(...args)))
}

export default function nest (...keys) {
  const nestFuncs = keys.map(
    (key) => (updateFunction) => wrapPayloadCreator(key, updateFunction)
  )
  return compose(...nestFuncs)
}

{'fraction_non_alphanumeric': 0.14647058823529413, 'fraction_numerical': 0.0035294117647058825, 'mean_word_length': 4.002941176470588, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '2673490', 'n_tokens_mistral': 559, 'n_tokens_neox': 539, 'n_words': 153}