<div dir="ltr">Hi,<div><div><div dir="ltr"></div></div></div>
<div><br></div><div>I came across hit issue while chaining filter() and prefix() on lazy sequences:</div><div><a href="https://bugs.swift.org/browse/SR-461" target="_blank">https://bugs.swift.org/browse/SR-461</a><br></div><div><br></div><div>And started wondering if it would be more consistent if lazy.filter().prefix() returned a custom LazySequenceType<Generator.Element> instead of Slice<LazyFilterCollection<Range<Generator.Element>>>.</div><div><br></div><div>That way lazy.filter().prefix() could be used to chain <b>pure lazy operations</b>, which can be actually quite useful in some cases.</div><div><br></div><div>I understand that this has implications, and it would make prefix() less consistent in terms of return type, but it would eliminate confusion like <a href="https://bugs.swift.org/browse/SR-461" target="_blank">SR-461</a>.</div><div>Also, this wouldn't be a much different than how how lazy.filter() is implemented, since it also returns a custom LazySequenceType instead of SequenceType.</div><div><br></div><div>Has this been considered before? Would there be any cases where this would create unintended side effects?</div><div>As far as I see, it wouldn't change the meaning of prefix(), only would it extend its usefulness. </div><div><br></div><div>I submitted a PR to the SwiftSequence library that demonstrates the implementation of this: <a href="https://github.com/itchingpixels/SwiftSequence/commit/26101e5aec6c266048bbad4db7b44b9c453f07ca" target="_blank">https://github.com/itchingpixels/SwiftSequence/commit/26101e5aec6c266048bbad4db7b44b9c453f07ca</a></div><div><br></div><div>And I'm happy to contribute to contribute it to stdlib if people find it useful.</div><div><br></div><div>Thanks a lot!</div><div><br></div><div>Mark</div></div>