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.

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

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

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

Idiom created by