This language bar is your friend. Select your favorite languages!

Idiom #165 Last element of list

Assign to variable x the last element of list items.

x = items.last
x = items[-1]
int[42] items;
int x = items[$-1];
import std.range;
int[] items;
auto x = items.back();
x = items.last;
x := items[len(items)-1]
foo :: [a] -> Maybe a
foo [] = Nothing
foo xs = Just $ last xs

x = foo items
-1
var x = items[items.length - 1];
x := items[high(items)];
x = items[-1]
val x = items.takeRight(1)

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

programming-idioms.org