copyWith method

CircularList<T> copyWith({
  1. int? capacity,
  2. void onElementRemoved(
    1. T
    )?,
  3. void onElementAdded(
    1. T
    )?,
})

Creates a copy of this list with optionally modified parameters.

The new list contains the same elements but can have different:

  • capacity
  • onElementRemoved callback
  • onElementAdded callback

Implementation

CircularList<T> copyWith({
  int? capacity,
  void Function(T)? onElementRemoved,
  void Function(T)? onElementAdded,
}) {
  final copy = CircularList<T>(
    capacity ?? this.capacity,
    onElementRemoved: onElementRemoved ?? this.onElementRemoved,
    onElementAdded: onElementAdded ?? this.onElementAdded,
  );
  copy.addAll(toList());
  return copy;
}