copy<T> function

ImmutableList<T> copy<T>(
  1. ImmutableList<T> list
)

Creates a copy of the given list.

This function returns a new ImmutableList<T> with the same elements as the provided list. This ensures that the original list remains unchanged while operations can be performed on the new list without affecting the original.

Usage:

var myList = ImmutableList([1, 2, 3, 4, 5]);
var copiedList = copy<int>(myList);
  • Parameter list: The list to be copied.
  • Returns: A new ImmutableList<T> containing the same elements as the input list.

Implementation

ImmutableList<T> copy<T>(ImmutableList<T> list) {
  return ImmutableList<T>(list.items);
}