<commit_before>var balanced = require('balanced-match')
var debug = require('debug')('aggsy.function')

var leading = /^[\s,]+/
var findName = /^[\w.]+(?=:)/

var reducers = require('./reducers')

function aggsy (agg, data) {
  debug(agg)
  var funcText = '\n'

  for (var name in reducers) {
    if (typeof reducers[name] !== 'function') { throw new Error('reducers must be functions') }
    funcText += reducers[name].toString() + '\n'
  }

  funcText += genFunction(agg)
  debug(funcText)
  var func = new Function ('result', 'item', funcText) // eslint-disable-line<commit_msg>Only add reducers that are used in function construction<commit_after>var balanced = require('balanced-match')
var debug = require('debug')('aggsy.function')

var leading = /^[\s,]+/
var findName = /^[\w.]+(?=:)/

var reducers = require('./reducers')

function aggsy (agg, data) {
  debug(agg)
  var funcText = '\n// reducers\n'

  for (var name in reducers) {
    if (typeof reducers[name] !== 'function') { throw new Error('reducers must be functions') }
    if (agg.indexOf(name) !== -1) {
      funcText += reducers[name].toString() + '\n'
    }
  }

  funcText += genFunction(agg)
  debug(funcText)
  var func = new Function ('result', 'item', funcText) // eslint-disable-line
{'fraction_non_alphanumeric': 0.18225039619651348, 'fraction_numerical': 0.000792393026941363, 'mean_word_length': 3.914396887159533, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6549134', 'n_tokens_mistral': 431, 'n_tokens_neox': 418, 'n_words': 115}