to method
Generates a list of integers from the current integer to maxInclusive with an optional step.
The maxInclusive parameter specifies the maximum value (inclusive) in the generated list.
The step parameter specifies the increment between each integer in the list. The default value is 1.
Returns a list of integers starting from the current integer up to maxInclusive, incremented by step.
Example:
int start = 1;
List<int> numbers = start.to(5);
print(numbers); // Output: [1, 2, 3, 4, 5]
List<int> numbersWithStep = start.to(10, step: 2);
print(numbersWithStep); // Output: [1, 3, 5, 7, 9]
Implementation
List<int> to(int maxInclusive, {int step = 1}) =>
[for (int i = this; i <= maxInclusive; i += step) i];