<?php

namespace Dash;

function groupBy($input, $groupBy)
{
	assertType($input, ['iterable']);

	return reduce($input, function($grouped, $value) use ($groupBy) {
		$key = get($value, $groupBy);
		$grouped[$key][] = $value;
		return $grouped;
	});
}

<?php

namespace Dash;

function groupBy($input, $groupBy, $defaultGroup = null)
{
	assertType($input, ['iterable']);

	return reduce($input, function($grouped, $value) use ($groupBy, $defaultGroup) {
		$key = get($value, $groupBy);
		$key = is_null($key) ? $defaultGroup : $key;
		$grouped[$key][] = $value;
		return $grouped;
	});
}

Add default value to groupby()
Add default value to groupby()

for null \$groupBy values