[Arr] group_by: throw when $key_fun returns a non-arraykey type

This commit is contained in:
azjezz 2020-07-06 19:30:42 +01:00
parent c5400a8571
commit 7c904b60e8

View File

@ -45,6 +45,8 @@ function group_by(iterable $values, callable $key_func): array
continue;
}
Psl\invariant(is_arraykey($key), 'Expected $key_func to return a value of type array-key, value of type (%s) returned.', gettype($key));
/** @psalm-var Tk $key */
$result[$key] = $result[$key] ?? [];
$result[$key][] = $value;
}