dropRight<T> function

ImmutableList<T> Function(ImmutableList<T>) dropRight<T>(
  1. int count
)

Returns a function that takes an ImmutableList<T> and returns a new ImmutableList<T> with the last count elements removed.

If count is greater than or equal to the length of the list, an empty ImmutableList<T> will be returned.

Usage:

var myList = ImmutableList([1, 2, 3, 4, 5]);
var dropLastTwo = dropRight<int>(2);
var newList = dropLastTwo(myList); // Returns ImmutableList([1, 2, 3])
  • Parameter count: The number of elements to drop from the right.
  • Returns: A function that processes an ImmutableList<T> and returns an ImmutableList<T> with the last count elements removed.

Implementation

ImmutableList<T> Function(ImmutableList<T>) dropRight<T>(int count) {
  return (ImmutableList<T> list) {
    if (count >= list.items.length) return ImmutableList<T>([]);
    return ImmutableList(list.items.sublist(0, list.items.length - count));
  };
}