prepend<T> function
- T item
Prepends an item to the beginning of a NonEmptyList.
Takes a NonEmptyList and returns a new NonEmptyList with the given item added to the beginning.
Example:
final list = NonEmptyList<int>([2, 3, 4]);
final prepended = prepend(1)(list);
print(prepended.items); // Outputs: [1, 2, 3, 4]
Implementation
NonEmptyList<T> Function(NonEmptyList<T>) prepend<T>(T item) =>
(NonEmptyList<T> list) => NonEmptyList([item, ...list.items]);