Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Because of this I always thought lists should be iterable/traversable, but have no direct (numeric) index to their items.


Like a stream?


Yes, like a stream, or an iterator. Where you fetch also a reverse iterator if you wish, filter by some predicate etc. A lot of overlap with both relational algebra/sql and with functional programming filter/map/reduce, I guess. Indexes seem convenient, but they're a hack in most cases.

Consider what happens when you sort your array, or delete or insert an item in the middle, or start. Now all your indexes have changed.

React had this issue, and this is why they had to add stable "key" to collections so that when you mutate a sequence of <li/> items for example, it doesn't get confused which is which.


think Set in Java does this

EDIT: Other than the obvious




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: