[swift-users] 2 x lazy collection bugs

Howard Lovatt howard.lovatt at gmail.com
Tue Feb 9 01:06:34 CST 2016


I am using StrideThrough which is a SequenceType and therefore the quotes I
used in the previous email were from the SequenceType documentation. There
is no random access for a SequenceType, all you can do is call a generator.
Which is what `for` does and therefore the generator must return elements
in the sequence defined by the underlying struct or class, in this case
StrideThrough. The documentation for StrideThrough says "A SequenceType of
values formed by striding over a closed interval." Which to me implies in
order since you take one stride and then another of the same size; it isn't
called RandomWalk!

Anyway: you can see from the printout that it is sequential.

But it does two passes and generates an out of bounds!

  -- Howard.

On 9 February 2016 at 17:39, Jens Alfke <jens at mooseyard.com> wrote:

> Did you mean to reply just to me?
>
> On Feb 8, 2016, at 10:33 PM, Howard Lovatt <howard.lovatt at gmail.com>
> wrote:
>
> which means it must be in-order (for loops are allowed side effects). Also
> why would you call something SequenceType if it wasn't sequential?
>
>
> The fact that the collection *can* be accessed sequentially doesn’t
> guarantee that it will be. If you called a binary search function on it,
> the comparison function wouldn’t be called in order, for example.
>
> It also categorically says that you can't iterate multiple times reliably:
>
>
> I’ve lost track of what method you’re calling, to be honest. Maybe it’s
> defined on Collection, not Sequence.
>
> —Jens
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160209/bcf5d5ae/attachment.html>


More information about the swift-users mailing list