From bdfdabc970ef286de9390ff0ab7740ff1145d388 Mon Sep 17 00:00:00 2001 From: Oskar Haarklou Veileborg Date: Thu, 12 Jan 2023 10:59:36 +0100 Subject: list: fix Append & Prepend, remove varargs support Similar reason for the API change as the previous commit. --- immutable.go | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'immutable.go') diff --git a/immutable.go b/immutable.go index e43bc70..666bb49 100644 --- a/immutable.go +++ b/immutable.go @@ -117,12 +117,8 @@ func (l *List[T]) set(index int, value T, mutable bool) *List[T] { } // Append returns a new list with value added to the end of the list. -func (l *List[T]) Append(values ...T) *List[T] { - other := l.clone() - for _, value := range values { - other.append(value, true) - } - return other +func (l *List[T]) Append(value T) *List[T] { + return l.append(value, false) } func (l *List[T]) append(value T, mutable bool) *List[T] { @@ -145,12 +141,8 @@ func (l *List[T]) append(value T, mutable bool) *List[T] { } // Prepend returns a new list with value(s) added to the beginning of the list. -func (l *List[T]) Prepend(values ...T) *List[T] { - other := l.clone() - for i := len(values) - 1; i >= 0; i-- { - other.prepend(values[i], true) - } - return other +func (l *List[T]) Prepend(value T) *List[T] { + return l.prepend(value, false) } func (l *List[T]) prepend(value T, mutable bool) *List[T] { -- cgit v1.2.3