'use strict';

var _arrayAggregator = require('./_arrayAggregator.js');
var _baseAggregator = require('./_baseAggregator.js');
var _baseIteratee = require('./_baseIteratee.js');
var isArray = require('./isArray.js');

/**
 * Creates a function like `_.groupBy`.
 *
 * @private
 * @param {Function} setter The function to set accumulator values.
 * @param {Function} [initializer] The accumulator object initializer.
 * @returns {Function} Returns the new aggregator function.
 */
function createAggregator(setter, initializer) {
  return function(collection, iteratee) {
    var func = isArray(collection) ? _arrayAggregator : _baseAggregator,
        accumulator = initializer ? initializer() : {};

    return func(collection, setter, _baseIteratee(iteratee), accumulator);
  };
}

module.exports = createAggregator;
