limit method

List<T> limit(
  1. int start,
  2. int end
)

Extract only the elements from start to end of Iterable.

Iterablestartからendまでの要素のみを抽出します。

final colors = <String>["red", "green", "blue", "orange", "pink"];
print(colors.limit(1, 3)); // [green, blue]

Implementation

List<T> limit(int start, int end) {
  if (this is List) {
    return (this as List).sublist(start, min(length, end)).cast<T>();
  } else {
    return toList().sublist(start, min(length, end));
  }
}