Logo

Programming-Idioms

History of Idiom 224 > diff from v1 to v2

Edit summary for version 2 by programming-idioms.org:
New Go implementation by user [programming-idioms.org]

Version 1

2020-04-15, 21:34:54

Version 2

2020-04-15, 21:42:05

Idiom #224 Add element to the beginning of the list

Insert element x at the beginning of list items.

Idiom #224 Add element to the beginning of the list

Insert element x at the beginning of list items.

Extra Keywords
prepend prefix start
Extra Keywords
prepend prefix start
Code
items = append([]T{x}, items...)
Comments bubble
items has type []T.
This implementation always allocates a full new slice.
Demo URL
https://play.golang.org/p/Lb6eLTWwmhG