plus method
Returns a new list consisting of the elements of this
added to
the elements of other
.
Note: The operator +
is already in use and concatenates two lists.
Implementation
List<num> plus(List<num> other) {
mustHaveSameLength(other, operatorSymbol: '+');
if (this is List<int> && other is List<int>) {
return List<int>.generate(length, (i) => (this[i] as int) + other[i]);
}
if (other is List<double>) {
return List<double>.generate(
length,
(i) => other[i] + this[i],
);
}
if (this is List<double>) {
return List<double>.generate(
length, (i) => (this[i] as double) + other[i]);
}
return List<num>.generate(length, (i) => this[i] + other[i]);
}