<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Aug 15, 2016 at 8:43 PM, Tim Vermeulen <span dir="ltr">&lt;<a href="mailto:tvermeulen@me.com" target="_blank">tvermeulen@me.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>Point taken, in theory it is possible that someone’s program would change unexpectedly if we change the function’s signature. But wouldn’t you agree that this was a very contrived example? I can’t think of a lot more than converting it to a string that works on both optionals and non-optionals.</div><div><br></div><div>`sequence(first:next:)` has only been available in Swift 3 beta versions, which are known to change over time. Shouldn’t we be focused on getting the function signature just right before Swift 3 is released?</div></div></blockquote><div><br></div><div>If you can slip it in before the deadline, I think I&#39;d be in favor. IIUC, the window for landing that change is days if not hours. If it misses the deadline, IMO checking for nil isn&#39;t terrible, but making a source-breaking change would be.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div class="h5"><div><blockquote type="cite"><div>On 16 Aug 2016, at 02:41, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>&gt; wrote:</div><br><div><div dir="ltr" style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div class="gmail_extra"><div class="gmail_quote">On Mon, Aug 15, 2016 at 7:23 PM, Tim Vermeulen<span> </span><span dir="ltr">&lt;<a href="mailto:tvermeulen@me.com" target="_blank">tvermeulen@me.com</a>&gt;</span><span> </span><wbr>wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><span><blockquote type="cite"><div>On 16 Aug 2016, at 02:11, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>&gt; wrote:</div><br><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Aug 15, 2016 at 7:03 PM, Tim Vermeulen<span> </span><span dir="ltr">&lt;<a href="mailto:tvermeulen@me.com" target="_blank">tvermeulen@me.com</a>&gt;</span><span> </span><wbr>wrote:<br><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 dir="auto"><div><div style="direction:inherit">If I&#39;m not mistaken, the type of T can be inferred from the `next` closure here. $0 is an optional, so you end up with a sequence of optionals.</div></div></div></blockquote><div><br></div><div>Currently, yes. But if we have both </div><div><br></div><div><div>public func sequence&lt;T&gt;(first: T, next: @escaping (T) -&gt; T?) -&gt; UnfoldFirstSequence&lt;T&gt; { ... }</div><div>public func sequence&lt;T&gt;(first: T?, next: @escaping (T) -&gt; T?) -&gt; UnfoldFirstSequence&lt;T&gt; { ... }</div></div><div><br></div><div>then $0 could be inferred to be of type `T` or `T?`, right?</div></div></div></div></div></blockquote><div><br></div></span><div>I was indeed talking about replacing the first function by the second, not having them side by side.</div><span><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>And if we replace the first function with the second (instead of having both), then the same code that gives you an UnfoldFirstSequence&lt;T?&gt; today would give you an UnfoldFirstSequence&lt;T&gt; tomorrow, which would be the most pernicious way to break code (subtle, hard to catch unless you know what you&#39;re looking for, with a potentially massive difference in behavior).</div></div></div></div></div></blockquote><div><br></div></span><div>I’m not sure I follow. First of all, I think an unfold sequence with an optional element is pretty far-fetched, but fair enough, they may exist. But why would the type suddenly change? Type inference would still figure out the right type, no? An example would be greatly appreciated, because I don’t see how this could form a problem.</div></div></div></blockquote><div><br></div><div><br></div><div>```</div><div>// This function is silly,</div><div>// but useful functions may take a similar form</div><div>func foo(_ x: Int?) -&gt; Int? {</div><div>  guard let x = x else { return 0 }</div><div>  return x &gt; 12 ? nil : x + 1</div><div>}</div><div><br></div><div>let a: Int? = nil</div><div>for i in sequence(first: a, next: { foo($0) }) {</div><div>  // This is a pretty useless thing to do,</div><div>  // but there are useful things that can be done</div><div>  // without checking whether `i == nil`</div><div>  print(i)</div><div>}</div><div>```</div><div><br></div><div>If you change the function signature, the number of lines printed by this example code will change from 14 to 0.</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div><div><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><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 dir="auto"><div><div><div>On 16 Aug 2016, at 00:51, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div>Given:<br><br>let foo: T? = something()<br>let bar = sequence(first: foo, next: { $0?.frobnicate() })<br><br>If first could be of type `T` or `T?`, is bar of type `UnfoldSequence&lt;T&gt;` or `UnfoldSequence&lt;T?&gt;`?<br><div class="gmail_quote"><div dir="ltr">On Mon, Aug 15, 2016 at 17:15 Tim Vermeulen via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br></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 style="word-wrap:break-word"><div>I doubt that’s it, in no way is an an empty sequence inherently unsafe. The entire standard library is built with empty sequences in mind. I’m more inclined to think it’s an oversight.</div></div><div style="word-wrap:break-word"><br><div><blockquote type="cite"><div>On 15 Aug 2016, at 23:15, Maximilian Hünenberger &lt;<a href="mailto:m.huenenberger@me.com" target="_blank">m.huenenberger@me.com</a>&gt; wrote:</div><br><div><div dir="auto"><div></div><div>Ok, I see. However this could be a potential source of bugs/performance issues where you don&#39;t consider the nil case and you do some unnecessary work. By prohibiting to pass nil you have to manually unwrap and you immediately see the &quot;optionality&quot;.</div><div><br>Am 15.08.2016 um 22:36 schrieb Tim Vermeulen &lt;<a href="mailto:tvermeulen@me.com" target="_blank">tvermeulen@me.com</a>&gt;:<br><br></div><blockquote type="cite"><div><div>Oh, that’s true, I misunderstood your previous message. It’s not about passing nil, but it’s about passing optionals. The point is to be able to do something like this:</div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(186,45,162)">let</span><span><span> </span>number = functionThatReturnsAnOptional(<wbr>)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>sequence(first:<span> </span></span><span style="color:rgb(79,129,135)">number</span><span>, next: { $0 %<span> </span></span><span style="color:rgb(39,42,216)">2</span><span><span> </span>==<span> </span></span><span style="color:rgb(39,42,216)">0</span><span><span> </span>? $0 /<span> </span></span><span style="color:rgb(39,42,216)">2</span><span><span> </span>:<span> </span></span><span style="color:rgb(186,45,162)">nil</span><span><span> </span>})</span></div></div><br><div><blockquote type="cite"><div>On 15 Aug 2016, at 22:26, Maximilian Hünenberger &lt;<a href="mailto:m.huenenberger@me.com" target="_blank">m.huenenberger@me.com</a>&gt; wrote:</div><br><div><div>Probably I didn&#39;t understand your proposal. What do you want to change exactly?<br><br>I thought:<br>public func sequence&lt;T&gt;(first: T, next: @escaping (T) -&gt; T?) -&gt; UnfoldFirstSequence&lt;T&gt; { ... }<br><br>To:<br>public func sequence&lt;T&gt;(first: T?, next: @escaping (T) -&gt; T?) -&gt; UnfoldFirstSequence&lt;T&gt; { ... }<br><br><blockquote type="cite">Am 15.08.2016 um 22:17 schrieb Tim Vermeulen &lt;<a href="mailto:tvermeulen@me.com" target="_blank">tvermeulen@me.com</a>&gt;:<br><br>You can’t; the `first` parameter has type `T`, not `T?`.<br><br><blockquote type="cite">On 15 Aug 2016, at 22:10, Maximilian Hünenberger &lt;<a href="mailto:m.huenenberger@me.com" target="_blank">m.huenenberger@me.com</a>&gt; wrote:<br><br>Hi Tim,<br><br>If you pass &quot;nil&quot; to &quot;first&quot; isn&#39;t this an empty sequence? So it would be redundant.<br><br>Best regards<br>Maximilian<br><br><blockquote type="cite">Am 15.08.2016 um 01:27 schrieb Tim Vermeulen via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;:<br><br>sequence(first:next:) takes a non-optional first argument. Is there a reason for that? sequence(state:next:) allows empty sequences, and I don’t see why sequence(first:next:) shouldn’t. The fix would be to simply add the `?` in the function signature; no other changes are required to make it work.<br><br>I considered just filing a bug report, but since this is a change of the public API...<br>______________________________<wbr>_________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-evolution</a><br></blockquote></blockquote><br></blockquote></div></div></blockquote></div><br></div></blockquote></div></div></blockquote></div><br></div>______________________________<wbr>_________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-evolution</a></blockquote></div></div></blockquote></div></div></div></blockquote></div></div></div></div></blockquote></div></div></div></div></blockquote></div></div></div></div></blockquote></div><br></div></div></div></blockquote></div><br></div></div>