diff options
author | Oskar Haarklou Veileborg <ohv1020@hotmail.com> | 2023-01-12 10:59:36 +0100 |
---|---|---|
committer | Oskar Haarklou Veileborg <ohv1020@hotmail.com> | 2023-01-12 10:59:36 +0100 |
commit | bdfdabc970ef286de9390ff0ab7740ff1145d388 (patch) | |
tree | 2e52253411977a11520a26fa368a214c9671c5bb /immutable.go | |
parent | sets & maps: remove varargs APIs & SetMany variants (diff) | |
download | pds-bdfdabc970ef286de9390ff0ab7740ff1145d388.tar.gz pds-bdfdabc970ef286de9390ff0ab7740ff1145d388.tar.xz |
list: fix Append & Prepend, remove varargs support
Similar reason for the API change as the previous commit.
Diffstat (limited to 'immutable.go')
-rw-r--r-- | immutable.go | 16 |
1 files changed, 4 insertions, 12 deletions
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] { |