<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><div>On Thu, May 19, 2016, at 05:52 PM, Kevin Ballard wrote (on a different thread):<br></div>
<blockquote type="cite"><div>After having given this some thought, it seems apparent that `sequence(state:next:)` is  equivalent to `AnyIterator({ ... })` where the closure captures a single mutable variable. The microbenchmark performance may differ slightly, as the AnyIterator version will allocate a box on the heap to hold the captured variable (assuming it can't get inlined entirely), whereas UnfoldSequence won't. But the functionality is the same.&nbsp;<br></div>
</blockquote><div>&nbsp;</div>
<div>For the record, I just realized that the type signature of UnfoldSequence&lt;T&gt; actually requires that we do heap allocation as well, because this type can only be used for the stateful version if we erase the state type by capturing it in a closure.<br></div>
<div>&nbsp;</div>
<div>As part of implementing this, I'm going to go ahead and modify the type signature to UnfoldSequence&lt;T, State&gt;, with `state(first:next:)` returning the type UnfoldSequence&lt;T, T?&gt;. I think it's better to diverge slightly from the proposal than it is to introduce unnecessary (albeit small) performance cost. I hope there are no objections.<br></div>
<div>&nbsp;</div>
<div>-Kevin Ballard<br></div>
</body>
</html>