Deep recursive transformation: make A into B while preserving the original object reference