Implement mapAccumWithKey, mapAccum and mapAccumRWithKey