iterate over matrix using lazy way