- Pitch: Mutating forEach

Interesting, I've never heard that reason. I think it's bogus reason though. We shouldn't have bad API as a lesser evil to offer to people blatantly misusing other APIs.

There is another reason why forEach used to be justified which is that it used to be a customization point. In theory that meant it could be faster than using an iterator, if some exotic data structure chose to provide a different implementation. In fact this theoretical speed benefit was even taken advantage of in the standard library in a couple of places. But it was removed as a customization point in SE-0232 so that no longer applies.

The other two justifications are what I thought was the main one (sticking it on the end of chains... which doesn't apply to a mutation variant) and the use with optionals, which ideally would have a better solution.

3 Likes