Add mapAccumLM helper function.