Should Dictionary support first related methods from Collection conformance?

One would think that, wouldn't one?! It turns out, though, that if you want one protocol to support forin loops, and you want to be able to uniformly loop over both an immutable Array and a single-pass stream that is consumed by iteration, you end up needing Sequence: a thing you can get an iterator from without mutating it (try working out the design—you'll see!)…

unless, that is, you have first-class language support for move-only types, by which I mean:

  • There's a category of operations, known to the type system, that consume values of move-only type (ending their lifetime), but automatically receive a copy of any copyable value.
  • Single-pass algorithms (and forin) belong to that category.
  • Single-pass sequences are move-only types.
2 Likes