# Two-way streams

I.e., streams that have a promise for previous items and one for next items. They could be useful for, say, all integers, where you have them going in both directions.

What would you use two-way streams for?

No, that can't work. If it's infinite in both directions, there's no first item so there's no way to start working on it.

The rule is that the stream implicitly promises that if you start at the beginning and keep cdring the stream, you'll get to any desired item in a finite amount of time.

How do you use one-way streams to make all the integers? You can't start at $$-\infty$$ because $$\pm\infty$$ isn't something you can get, but rather something you approach.

0, 1, -1, 2, -2, ...

This has the property that any integer will be reached in finite time. It doesn't have them in "natural" order, but that's not what streams are for. If you think it's unreasonable of me to say that, think about the stream of all the rational numbers. There are only countably many of them, so they "fit" in a stream, but there's no way to begin, under the constraint of following natural order.

I should have said "in order", i.e., ... -2 before -1 before 0 before 1 before 2 ...

(I wrote that before I read

)

Oh and what about fibonacci numbers in both directions? ... 5 -3 2 -1 1 0 1 1 2 3 5 ...

Same thing, interleave positive and negative positions.

But still, -1 being after 1 makes no intuitive sense, unless in some function.

I dunno what to tell you. The purpose of streams is to give you a finite encoding (so you can actually use one in a computer) of an infinite set, with the promise that any element is reachable in finite time. It's too much to ask that they also preserve natural order.

You can, of course, build a data structure consisting of two streams, one for nonnegative items and one for negative items. But that data structure won't be able to promise to reach any element in finite time, unless you traverse both streams in parallel -- which is the same as alternating items in a single stream.

Ugh. I just lost my 2stream project.

You know about the Recover feature, right?

I hadn't even saved it, and it crashed Snap!. (Hopefully I learned my lesson: don't un-WARP a custom block in visible stepping)

That sounds like a bug report...

Yeah, it does. I'll make one.