dropRight method

  1. @override
ILazyList<A> dropRight(
  1. int n
)
override

Return a new collection with the last n elements removed.

Implementation

@override
ILazyList<A> dropRight(int n) {
  if (n <= 0) {
    return this;
  } else if (knownIsEmpty) {
    return empty();
  } else {
    return _newLL(() {
      var scout = this;
      var remaining = n;

      // advance scout n elements ahead (or until empty)
      while (remaining > 0 && !scout.isEmpty) {
        remaining -= 1;
        scout = scout.tail;
      }

      return _dropRightState(scout);
    });
  }
}