Unfortunately, it is not exactly the same as the existing one: there is no check for `null` in the primitive case. I was unsure how to factor it out. If you have a suggestion, I'll take it.