modify scanLeft to correctly handle empty partitions