On the advent of code day three it would be useful to have a chunking iterator in rust. Having just implemented day 3 and looking for one, I knew rust stable doesn’t have a general purpose chunking iterator.
I asked chatGPT about it and it very confidently said one existed and gave me a sample code which imported a nonexistent chunking iterator. I wonder about other outputs of chatGPT which are not as easily and quickly verifiable.
When I asked it how to undo an operation I had performed using "cargo add" it confidently showed me examples of using the "cargo remove" command... which it had entirely made up.
As the parent said, it's not stable yet but it's right there so you can see how it works.
The most important ergonomic trick here is that Rust has type inference, it can see array_chunks needs to know how big the chunks should be, and of course you can just specify that but in most cases you'll use chunks which clearly have a defined size and the inference will go "Oh, that's how big the chunks are" just as e.g. if you put a bunch of chars in a Vec you made, the type inference goes, "Oh, it's a Vec of chars" and doesn't waste your time asking you what type of Vec it is.
You'll see the example expects Some(['l', 'o']) to be the first thing out of the Iterator, the type inference system can see that's an array of two chars, thus, the chunk size is 2.
I asked chatGPT about it and it very confidently said one existed and gave me a sample code which imported a nonexistent chunking iterator. I wonder about other outputs of chatGPT which are not as easily and quickly verifiable.