Calculates the composition of two functions.