Overloading can feel good in the spur of the moment, but only ever leads to long term pain.
I'm a bit surprised people don't think discovery via code completion and complementing forEach()
is valuable. Ah well
As a native English speaker, let me weigh in here. Your suggestion of using form... makes no sense to me. Neither formEach, nor formForEach, nor any other formulation. Whether it makes grammatical sense or not, it looks awkward, and it's a phrasing no English speaker I've ever interacted with would use.
Well, you may now consider yourself to have interacted with one such native English speaker who would use that phrasing :)
It'd be nice if there was a similar way to mutate dictionary values.
This will work for Dictionary
values, as the collection returned by Dictionary.values
conforms to MutableCollection
.
Has anyone suggested withEach
?
mutableArray.withEach { $0 = $0.lowerCased() }
In fact, Dictionary.values
is one of the places in the standard library where this proposal will be most beneficial, by avoiding the attractive nuisance of iterating over indices
or keys
(either of which would make an unnecessary copy of the dictionary when you mutate a value).
For what it's worth, in a past life of much reading and writing I earned a degree in English and American literature, and neither formForEach
nor formMap
make much sense to me alongside the other form
-prefixed methods, nor do they read well. I think this is why you're getting what appears to be universal pushback here.
How about we push this forward? I believe it's a small but valuable addition to the standard library.
Will be happy to help with proposal if needed
The proposal doesn’t really require help: it’s a small addition with an easy code change.
I’ve mostly avoided this because @Ben_Cohen has suggested he’s pretty strongly not in favour of the change. Even if the community as a whole was, I think @Ben_Cohen’s opinion is extremely important. If he’s not strongly against this I’m happy to resurrect the pitch, but as long as he doesn’t indicate anything else I think this is dead for me.