Optimized 'TransformedWith' algorithm.