combineLists<T> function

List<T> combineLists<T>(
  1. List<T> l1,
  2. List<T> l2,
  3. Combiner<T> combiner
)

Implementation

List<T> combineLists<T>(List<T> l1, List<T> l2, Combiner<T> combiner) {
  if (l1.length != l2.length) {
    throw "lists of different lengths";
  }
  if (l1.isEmpty) return l2;
  if (l2.isEmpty) return l1;

  List<T> ret = [];
  for (int i = 0; i < l1.length; i++) {
    ret.add(combiner(l1[i], l2[i]));
  }
  return ret;
}