This language bar is your friend. Select your favorite languages!
Select your favorite languages :
- Or search :
- Clojure
- C++
- C++
- C#
- C#
- D
- Dart
- Elixir
- Fortran
- Go
- Go
- Go
- Go
- Haskell
- Haskell
- JS
- JS
- Java
- Lisp
- Lua
- PHP
- Pascal
- Perl
- Python
- Python
- Ruby
- Ruby
- Rust
- Scala
- VB
- VB
items = items.Prepend(x).ToList();
items implements IEnumerable<T>.
Omitting ToList() results in a wrapper IEnumerable<T> with the element prepended.
Omitting ToList() results in a wrapper IEnumerable<T> with the element prepended.
items = append([]T{x}, items...)
items has type []T.
This implementation always allocates a full new slice.
This implementation always allocates a full new slice.
func prepend[S ~[]T, T any](items *S, x ...T) {
*items = append(*items, x...)
copy((*items)[len(x):], *items)
copy(*items, x)
}
This generic func does not always allocate (depending on the capacity of items).
The variadic argument x accepts one or more values to insert at the beginning.
The variadic argument x accepts one or more values to insert at the beginning.
func prepend[S ~[]T, T any](items *S, x ...T) {
*items = append(x, *items...)
}
This generic func always allocates a full new slice.
The variadic argument x accepts one or more values to be inserted at the beginning.
The variadic argument x accepts one or more values to be inserted at the beginning.
items = append(items, x)
copy(items[1:], items)
items[0] = x
This implementation is verbose, but it will often not allocate, when items has enough capacity.
items = items.Prepend(x).ToList()
items implements IEnumerable<T>.
Omitting ToList() results in a wrapper IEnumerable<T> with the element prepended.
Omitting ToList() results in a wrapper IEnumerable<T> with the element prepended.
programming-idioms.org