Logo

Programming-Idioms

History of Idiom 165 > diff from v14 to v15

Edit summary for version 15 by foo:
[Haskell] more correct

Version 14

2017-12-22, 10:45:55

Version 15

2017-12-22, 10:47:58

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 [] = []
foo xs = 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 - list of homogenious elms
x - the last elm of this list