runLengthDecode<T> function

List<T> runLengthDecode<T>(
  1. Iterable<(T, int)> pairs
)

Run-length decode: expand (value, count) pairs into a list.

Example:

runLengthDecode([(1, 2), (2, 3)]); // [1, 1, 2, 2, 2]

Implementation

List<T> runLengthDecode<T>(Iterable<(T, int)> pairs) {
  final List<T> result = <T>[];
  for (final (T value, int count) in pairs) {
    for (int i = 0; i < count; i++) {
      result.add(value);
    }
  }
  return result;
}