Here is the map method which seems to be duplicate in Sequence protocol. How is apple doing this? what is the intention behind this?
public protocol Sequence {
public func map<T>(_ transform: (Self.Iterator.Element) throws -> T) rethrows -> [T]
}
extension Sequence {
public func map<T>(_ transform: (Self.Iterator.Element) throws -> T) rethrows -> [T]
}
The protocol Sequence both requires a map
function and (using a protocol extension) supplies a default implementation for it. That is what protocol extensions are for.