append<T> function

NonEmptyList<T> Function(NonEmptyList<T>) append<T>(
  1. T item
)

Appends an item to the end of a NonEmptyList.

Takes a NonEmptyList and returns a new NonEmptyList with the given item added to the end.

Example:

final list = NonEmptyList<int>([1, 2, 3]);
final appended = append(4)(list);
print(appended.items);  // Outputs: [1, 2, 3, 4]

Implementation

NonEmptyList<T> Function(NonEmptyList<T>) append<T>(T item) =>
    (NonEmptyList<T> list) => NonEmptyList([...list.items, item]);