[swift-evolution] [Review] SE-0032: Add find method to SequenceType

Kevin Ballard kevin at sb.org
Fri Apr 29 19:36:22 CDT 2016

On Thu, Apr 28, 2016, at 10:31 PM, Rod Brown via swift-evolution wrote:
> * What is your evaluation of the proposal?
> +1 for the functionality on CollectionType
> -1 for the functionality on SequenceType
> * Is the problem being addressed significant enough to warrant a change to Swift?
> It’s certainly a helpful addition and one I’ve got an analogous version of in my own projects. Considering this is a simply addition on CollectionType, I think there no reasons not to.
> I’m concerned about this being added to SequenceType. The risks associated with iterating through a sequence where it may be destructive seem to great to me, especially when this can be limited to CollectionType instead.

I don't understand this argument. The whole point of a sequence is to iterate over it. Yes, if you have a destructive sequence and you iterate over it multiple times it's not going to work right, but I don't see find() as having any higher risk of doing this than any of the other methods that iterate over the sequence.

Not only that, but I actually find the find() method to be most useful when used with Sequence. With Collection you can already just get the index and then use that to index into the collection; it's a little verbose, but not awful. But the only alternative with Sequence is to write an imperative loop that uses a mutable variable.


More information about the swift-evolution mailing list