@function __count-by-iteratee($result, $value, $key, $args...) {
    $result: if(
        map-has-key($result, $key),
        __set($result, $key, __get($result, $key) + 1),
        __set($result, $key, 1));

    @return $result;
}


@function __count-by($arguments...) {
    $function: __create-aggregator('__count-by-iteratee');

    @return __exec($function, $arguments...);
}


/// Creates a map composed of keys generated from the results of running
/// each element of `$collection` through `$iteratee`. The corresponding value
/// of each key is the number of times the key was returned by `$iteratee`.
/// The `$iteratee` is bound to `$this-arg` and invoked with three arguments;
/// (value, index|key, collection).
/// 
/// If a property name is provided for `$predicate` the created `_property`
/// style callback returns the property value of the given element.
/// 
/// If a value is also provided for `$this-arg` the created `_matches-property`
/// style callback returns `true` for elements that have a matching property
/// value, else `false`.
/// 
/// If a map is provided for `$predicate` the created `_matches` style
/// callback returns `true` for elements that have the properties of the given
/// map, else `false`.
///
///
/// @access public
/// @group Collection
/// @param {List|Map|string} $collection The collection to iterate over.
/// @param {Function|Map|string} $iteratee [_identity] - The function invoked
///  per iteration.
/// @param {*} $this-arg [null] The `_this` binding of `$iteratee`.
/// @returns {Map} Returns the composed aggregate map.
/// @example scss
/// $foo: _count-by((4.3, 6.1, 6.4), 'floor');
/// // => ( 4: 1, 6: 2 )
/// 
/// $foo: _count-by(('one', 'two', 'three'), 'str-length');
/// // => ( 3: 2, 5: 1 )
@function _count-by($args...) {
  @return call(get-function('__count-by'), $args...);
}
