BUG: Bug fix in apply when using custom function and objects are not mutated (GH5545)

closes #5545