<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><div>On Wed, Dec 30, 2015, at 02:27 PM, plx via swift-evolution wrote:<br></div>
<blockquote type="cite"><div>&nbsp;</div>
<div><blockquote type="cite"><div><div><div>On that note, core language team, anyone know offhand why SequenceType has a bunch of extension methods that aren't part of the protocol? For example, <span class="font" style="font-family:menlo, consolas, 'courier new', monospace, sans-serif">contains(_ predicate:)</span>. The only real reason I can think of is to shrink the protocol witness table, but surely that's not particularly meaningful. I warrant that <span class="font" style="font-family:menlo, consolas, 'courier new', monospace, sans-serif">contains(_ predicate:)</span> doesn't really have any reason to be overridden by anything except sequences that knowingly repeat elements (e.g. CycleSequence and Repeat), and even that's only if you assume the predicate is pure, but there's some other methods that make sense to override on some sequences (like <span class="font" style="font-family:menlo, consolas, 'courier new', monospace, sans-serif">minElement(_ isOrderedBefore:)</span> for any sequence that has a defined ordering).<br></div>
</div>
</div>
</blockquote><div>&nbsp;</div>
<div>I am not sure how, precisely, you would propose to override the closure-taking variant of `minElement` to take advantage of an intrinsic ordering, but I’d be curious to see it.<br></div>
</div>
</blockquote><div>&nbsp;</div>
<div>Oops, you're entirely right. I wasn't thinking carefully about it; it's the Comparable version that would be able to take advantage of an intrinsic ordering, but of course we can't override that using the current language rules as it requires the Equatable bound. Of course, once we add the ability to have conditional protocol conformance, then we can move things like that into a separate protocol and declare SequenceType as conforming to it whenever Element : Equatable, which would let those methods then become overridable.<br></div>
<div>&nbsp;</div>
<div>Although interestingly, contains() actually has a hack right now where it invokes a hidden SequenceType method called&nbsp;_customContainsEquatableElement(). This is explicitly intended to let sequences override the Equatable version of contains() if the sequence knows it can do better than a linear search.</div>
<div>&nbsp;</div>
<blockquote type="cite"><div><div>I’d hope that the non-closure-accepting variants would be made overridable once the type system supports it.<br></div>
</div>
</blockquote><div>&nbsp;</div>
<div>Agreed.<br></div>
<div>&nbsp;</div>
<div>-Kevin Ballard</div>
</body>
</html>