|
|
|
|
|
by swift
3536 days ago
|
|
I'm not so sure. Generally implementing an iterator when the iteration doesn't represent a straightforward walk over the elements of a collection is much more error-prone. The implementation of the lambda version looks exactly the same as if you were just performing the iteration locally, while the iterator version requires saving and restoring a bunch of state and handling more edge cases. At call sites, the iterator version looks a little better, but not so much so that I'd consider the additional implementation complexity (and hence potential for bugs) worth it. That said, this is definitely a controversial opinion and there are arguments in the other direction as well. |
|