I think this function would benefit from explanation, either in comments or chapter text.
It might be enough just to label the two code branches so that the reader doesn't need to figure out that one is for composition and the other is for application of the transform.