kriskowal / gtor

A General Theory of Reactivity

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Indices are a distraction

domenic opened this issue · comments

The narrative seems to be something like: "we have an existing iteration interface, { done, value }. This is missing index, so let's add it." But index never plays a role in any of the subsequent work and seems entirely useless; it's just an extra piece of information to be passed around. It definitely doesn't seem to be a fundamental part of the iteration interface on the same level as done and value.

Certainly is a distraction, not fundamental to anything so far written. I still need to write more about how index goes from being a position in space to a moment in time for signals and behaviors. Behaviors in particular benefit from being able to map a time to a value.

Right, that was the other thing. They appear as time in one signal example, but the time also seems redundant: you could just do Date.now(), since it is a signal, and there is no (or minimal) delay between the signal production and the callback being called.

For sensitive systems of behaviors, particularly in animation, every aspect of the system should be rendered based on a single snapshot of time. Consider an animation of an engine, piston, crankshaft, drive train.

OK, but in that case I would just bundle it into the value, and not make it a fundamental part of the protocol.

I am going to heed your words and minimize the discussion of index because it is a tangent. However, I do think it is worth embedding in the protocol itself. Another reason is that it is necessary to faithfully produce this equivalence:

array.forEach(function (value, index) {
    // ...
});
array.iterate().forEach(function (value, index) {
    // ...
})

I guess I don't really see that equivalence as very useful. If you move to iteration, you no longer get indices. Indices seem, at least intuitively, tied to the nature of arrays as random-access data structures; they don't make as much sense to me for iterables, even if in theory they could be added.

I wonder if any other languages' iterable/enumerable implementations include index in the protocol.

I wonder if any other languages' iterable/enumerable implementations
include index in the protocol.

Not to my knowledge.