Description
Let's start with just discussing combineList
, which is currently implemented in various forms internally, and has lots of utility and potential perf-saving.
//// Returns a new list that represents [lists] flattened into a single list.
///
/// All methods and accessors treat the new list as-if it were a single concatenated list,
/// but the underlying implementation delegates to each corresponding list as necessary.
List<T> combineLists<T>(List<List<T>> lists) => ...
Here is an example of implementing first
:
class _CombinedList<T> implements List<T> {
final List<T> _lists;
T get first {
for (final list in _lists) {
if (list.isNotEmpty) {
return list.first;
}
}
throw ...
}
}
/cc @nex3, @leonsenft, @ferhatb
FWIW I believe @isoos originally implemented something like this for the high-performance table, and it worked really well. I'd also eventually like to see the same thing for Map
and Iterable
if possible - though to simplify things they may need to be read-only, but worth discussing anyway.