slice method

ListSlice<E> slice(
  1. int start,
  2. [int? end]
)

A fixed length view of a range of this list.

The view is backed by this list, which must not change its length while the view is being used.

The view can be used to perform specific whole-list actions on a part of the list. For example, to see if a list contains more than one "marker" element, you can do:

someList.slice(someList.indexOf(marker) + 1).contains(marker)

Implementation

ListSlice<E> slice(int start, [int? end]) {
  end = RangeError.checkValidRange(start, end, length);
  var self = this;
  if (self is ListSlice<E>) return self.slice(start, end);
  return ListSlice<E>(this, start, end);
}