2
votes

Sequence's protocol

is a Swift protocol, so all the methods it are required.

Taking a look at its declaration, I've seen now that there are a lot of methods such as

makeIterator(), map(), filter()

and so on...

I'm wondering why only

makeIterator()

method is required.

It's not a @objc protocol with optional keyword, it's not a protocol's extension, it doesn't not conform any other protocols. It's a simple Swift kind of protocol.

Any idea?

1
"it's not a protocol's extension" – No, Sequence does provide default implementations for the rest of its requirements, e.g map's default implementation is here, filter's default implementation is here. Note that there's also a default implementation for makeIterator() when the sequence is its own iterator. - Hamish
Oh man! I was looking for the default implementation inside the same file but I was not able to find it. In fact above, I have written that it's not a protocol's extension because of I was finding the default implementation inside that file. Thank you so much! - ndPPPhz
@Hamish Seems like a perfectly valid answer, why not posting it? - Alladinian

1 Answers

1
votes

Regarding to the question, Hamish gives us the right solution

it's not a protocol's extension" – No, Sequence does provide default implementations for the rest of its requirements, e.g map's default implementation is here, filter's default implementation is here. Note that there's also a default implementation for makeIterator() when the sequence is its own iterator.

We can found the makeIterator() default implementation here

Really thanks!