libcore: add a ScanIterator, a generalisation of MapIterator to have internal state.
libcore: add methods for consuming iterators: foldl and to_vec.
libcore: convert iterator tests to use to_vec instead of iterating.

Unfortunately this requires dereferencing each element due to how the vec
iterators work. Also, add an explicit test for `advance` since it was no
longer being tested itself.