Logo

Programming-Idioms

Insert the element x at the beginning of the list items.
Implementation
Dart

Implementation edit is for fixing errors and enhancing with metadata. Please do not replace the code below with a different implementation.

Instead of changing the code of the snippet, consider creating another Dart implementation.

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
items.unshift(x);
items = append([]T{x}, items...)
items = append(items, x)
copy(items[1:], items)
items[0] = x
items = [x, items]
items.insert(0,x);
items.unshift(x)
items.prepend(x)
unshift @items, $x
items = [x] + items
#include <list>
items.emplace_front(x);
#include <list>
items.push_front(x);
items = [x, ...items];
use std::collections::VecDeque;
items.push_front(x);
items2 = x : items
items.Insert(0, x);
items2 = [x | items]
array_unshift($items, $x);
items.insert(0, x)
items.add(0, x);
using System.Linq;
items = items.Prepend(x).ToList();
items.Insert(0, x)
Imports System.Linq
items = items.Prepend(x).ToList()
items = x ~ items;
f(x:xs)= x:xs
(def items2 (conj items x))
func prepend[S ~[]T, T any](items *S, x ...T) {
	*items = append(x, *items...)
}
func prepend[S ~[]T, T any](items *S, x ...T) {
	*items = append(*items, x...)
	copy((*items)[len(x):], *items)
	copy(*items, x)
}
table.insert(items, 1, x)
val newList = x :: items