Hacker News new | ask | show | jobs
by chrismorgan 438 days ago
Another approach:

  let mut iterator = data.chunks_mut(stride);
  while let Some(line) = if !flipped { iterator.next() } else { iterator.next_back() } {
      …
  }
I sometimes wonder idly if the language would have been better off without a `for` loop (if `while let` had happened much earlier). `while let` is more verbose, mainly because iterator construction has to be an explicit separate line, but it’s also more amenable to alteration to make it more fit for purpose. (You can go down to `loop` and `break`, but I think this sacrifices too much in ergonomics and comprehensibility in the usual case. As `while let` also compromises, but I wonder if it’s closer to the sweet spot than commonly imagined, and `for` doesn’t actually get you so much.)