Logo

Programming-Idioms

History of Idiom 165 > diff from v39 to v40

Edit summary for version 40 by programming-idioms.org:
[Haskell] Comments

Version 39

2019-09-09, 09:13:49

Version 40

2019-09-09, 09:15:25

Idiom #165 Last element of list

Assign to variable x the last element of list items.

Idiom #165 Last element of list

Assign to variable x the last element of list items.

Code
foo :: [a] -> Maybe a
foo [] = Nothing
foo xs = Just $ last xs

x = foo items
Code
foo :: [a] -> Maybe a
foo [] = Nothing
foo xs = Just $ last xs

x = foo items
Comments bubble
items - list of homogenious elms
x - the last elm of this list
Comments bubble
items is a list of homogeneous elements