You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to iterate a Set, for example, in either direction, and change direction during iteration. This could, for example, replace a (maybe circular) linked list.
This example is obviously not very well thought out (next() returns {value: ___, ...}), but it shows what the end-user desire is:
constset=newSet(...)// maybe this comes from somewhere else (imported, component prop, etc)constvals=set.values()letselected=vals.next()// ... some reactive framework template ...return<div><p>name: {selected.name}</p><buttononclick={()=>selected=vals.next()}>next</button><buttononclick={()=>selected=vals.prev()}>prev</button></div>
The text was updated successfully, but these errors were encountered:
While this definitely works for an iterator over a finite collection (Set, Map, Array, String), in general it wouldn't work - in particular for most things that use generators or custom iterators. would you test for the presence of a prev method to distinguish?
I would like to iterate a
Set
, for example, in either direction, and change direction during iteration. This could, for example, replace a (maybe circular) linked list.More thoughts here:
https://es.discourse.group/t/next-prev-for-non-async-iterators/2224
Motivating example:
This example is obviously not very well thought out (
next()
returns{value: ___, ...}
), but it shows what the end-user desire is:The text was updated successfully, but these errors were encountered: