Elektrine lite

← Feed

@danderson@hachyderm.io

Post #3951951

2026-07-20 04:36 UTC

I started down this adventure because I had an Iterator>, and I wanted a Result>. So I thought "well I guess I'll try the thing that definitely won't work and just do `foo.iter().collect()`, but that'll make a Vec>"... And then it compiled fine and gave me the thing I wanted, so I was intrigued and wanted to find out why. One headache later, I kind-of regret asking.

Replies (1)

  • @danderson@hachyderm.io 2026-07-20 04:39

    To be clear the bemusing part is that `collect()` works by invoking `Vec::from_iterator(iter)`, and _that_ iterator is an iterator of just the values, not value-or-error. There is some kind of cursed magic taking place that transforms an iterator of Result into an iterator of V, which lets Vec construct itself streamily by iteration, but also short-circuits the entire computation and returns an error if it encounters one. I think? I'm so confused.

    Open ##3951950