Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Scala
val newList = x :: items

Scala uses an implementation of a linked list for its List type, so prepending x is guaranteed to be O(1) time.

The :: operator is pronounced "Cons"
(def items2 (conj items x))

conj take a list and an item, in that order, and appends the item to the list at the front.

New implementation...
< >
programming-idioms.org