joinToList method

Iterable<T> joinToList([
  1. T? separator
])

Merges an array of arrays into a single array and returns it.

When separator is passed, the elements of separator are inserted between the arrays to be merged.

配列の配列をマージして1つの配列にして返します。

separatorを渡すと、マージする配列と配列の間にseparatorの要素が挿入されます。

final arrayOfArray = [[1, 2, 3], [5, 6], [8, 9]];
final joined = arrayOfArray.joinToList(4); // [1, 2, 3, 4, 5, 6, 4, 8, 9]

Implementation

Iterable<T> joinToList([T? separator]) {
  final res = <T>[];
  for (final list in this) {
    res.addAll(list);
    if (separator != null) {
      res.add(separator);
    }
  }
  if (separator != null && res.isNotEmpty) {
    res.removeLast();
  }
  return res;
}