Implements catamorphism.