Implement mapAccumWithKey and mapAccum