Why not pass in Acc to extract_messages/1 since you use a new accumulator later on in there. Then you can avoid the append operation here at the end of the fold