// TODO: check key is a correct key, identity may lead this to be a non-string and non-integer value
// have a default for arrays and other scalars
if(!is_string($key)&&!is_integer($key)){
thrownewInvalidArgumentException("The key ".var_export($key,true)." cannot be used for collection, please specify a custom mapping function to collectFrequencies()");