<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Hi Tim,</div><div class=""><br class=""></div><div class="">Thanks for bringing this up.</div><div class="">Here are my thoughts on the change you’re proposing.</div><div class=""><br class=""></div><div class=""><font face="Menlo" class=""><span style="font-size: 12px;" class="">func sequence&lt;T&gt;(first: T, next: (T) -&gt; T?) -&gt; UnfoldFirstSequence&lt;T&gt;</span></font></div><div class=""><br class=""></div><div class="">To me the type of the function as it is tells a clear story of what’s going to happen: take the `first`, make it a head of the resulting sequence, and then try to produce the tail by a series of applications of `next`. The only thing that controls when the sequence generation terminates is the result of `next`.</div><div class=""><br class=""></div><div class="">If we change the type of `first` to an Optional&lt;T&gt;, it would make the termination condition non-trivial. After all, the only thing it would do is try to unwrap the `first`, before doing what it needs to, but we already have a `map` for that. One should be able to simply do the `first.map { sequence(first: $0, next: next) } ?? []` but that won’t work with the types very well, unfortunately.</div><div class=""><br class=""></div><div class="">As an alternative, `let first: Int? = ...; sequence(first: first, next: next).flatMap({$0})` (or even `.lazy.flatMap({$0})`) will do the right thing without making an API more complex.</div><div class=""><br class=""></div><div class="">I see the point of `sequence(first:next:)` to be precisely the "generate the non-empty sequence using a seed and a simple producer", for anything more than that, there is `sequence(state:next:)`.</div><div class=""><br class=""></div><div class="">What do you think?</div><div class=""><br class=""></div><div class="">Max</div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On Aug 14, 2016, at 4:27 PM, Tim Vermeulen via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">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 class=""><br class="">I considered just filing a bug report, but since this is a change of the public API...<br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></div></blockquote></div><br class=""></body></html>