Hacker News new | ask | show | jobs
by hombre_fatal 247 days ago
What does the second List impl offer over the first one?

It's the API that makes something impossible to misuse, and they could offer the same API like List.create(x: T, xs: T[]), but the first one is simpler.

1 comments

In one version I've seen, the active element is of a different type, offering enhanced functionality over the vectors of next and prev items:

  struct List<T, A> {
    prev: Vec<T>,
    active: A,
    next: Vec<T>,
  }
This could be used for some active type that has ephemeral cache information or state associated with it (view state in a GUI app, for instance). The inactive type may be hydrated and converted to active, and the active type can be archived into an inactive type.