<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 14. Oct 2017, at 21:55, Xiaodi Wu via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><div class=""><div style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_quote"><div dir="auto" class=""><br class="Apple-interchange-newline">On Sat, Oct 14, 2017 at 14:36 Benjamin G <<a href="mailto:benjamin.garrigues@gmail.com" class="">benjamin.garrigues@gmail.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div class="">I think what you're saying and what Kevin is saying are in way not contradictory : <div class=""><br class=""><div class="">You're saying the "SpongeBob" protocol functions make sense and are coherent, Kevin is saying the consequence is that it creates weird functions for Sets, and i think you're both right.<br class=""></div></div><div class=""><br class=""></div><div class="">an "UnorderedSequence" may very well have a "first" element. The problem is that when you apply it to sets, you're not calling:</div><div class=""><br class=""></div><div class="">mySet.generatedRandomOrderSequence().first()</div><div class=""><br class=""></div><div class="">but</div><div class=""><br class=""></div><div class="">mySet.first()</div><div class=""><br class=""></div><div class="">That's where the issue stands, and that's IMHO, a symptom that the protocol hierarchy is a bit misleading.</div><div class="">What you would like for sets isn't "first()", but "any()".</div><div class=""></div></div></blockquote><div dir="auto" class=""><br class=""></div><div dir="auto" class="">'first' is just a shorthand for 'let first; for element in sequence { first = element; break }'. Any type that offers iterated access in a for...in loop must, by construction, have a definable 'first'.</div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">Swift Sequences are deliberately allowed to be single-pass, infinite, or unordered. A multi-pass, finite Sequence is a Collection. It's not an oversight that 'first' is defined on Sequence and not Collection. It's not 'weird' to ask what the first element you get on iteration must be; by definition, iteration gives you elements sequentially and something must be first.</div></div></div></div></blockquote><br class=""></div><div>I don't think this really changes the point you're making, but the 'first' property is in fact defined on Collection and not Sequence. Sequence has 'first(where:)', 'dropFirst', and 'prefix' methods, and essentially the same argument applies to them.</div><div><br class=""></div><div>One rationale I heard (I think from Ben Cohen) for why 'first' is <i class="">not</i> defined on Collection is that Sequences can be single-pass, and it would feel weird for a seemingly innocuous property like 'first' to have side effects.</div><br class=""></body></html>