becheran / grid

Two dimensional grid data structure
MIT License
82 stars 27 forks source link

unmutable col_iter and row_iter #25

Closed IzaakC closed 1 year ago

IzaakC commented 1 year ago

Extend the functional programming abilities by adding iterators over the columns and the rows.

Two new methods are added to Grid::grid

  1. pub fn iter_rows(&self) -> GridRowIter<'_, T>
  2. pub fn iter_cols(&self) -> GridColIter<'_, T>

Where the new structs GridRowIter and GridColIter are wrappers around the existing grid.iter_col and grid.iter_row that keep track of the current index.

This feature reduces the risk of index errors when iterating over rows or columns.

Feedback and criticism is welcome. I'm planning on adding a mutable version of the two iterators in the future.

becheran commented 1 year ago

Thx! Looks good on first brief look. Will merge later if I have a bit more time to read the code.