tail<T> function

List<T> tail<T>(
  1. NonEmptyList<T> list
)

Returns all items from list except the first.

Throws ArgumentError if the list contains only one item.

var nel = NonEmptyList([1, 2, 3]);
print(tail(nel));  // [2, 3]

Implementation

List<T> tail<T>(NonEmptyList<T> list) {
  if (list._items.length == 1) {
    throw ArgumentError('Tail of a single-element list is empty.');
  }
  return list._items.sublist(1);
}