Logo

Programming-Idioms

History of Idiom 165 > diff from v13 to v14

Edit summary for version 14 by foo:
[Haskell] better way

Version 13

2017-12-22, 10:40:34

Version 14

2017-12-22, 10:45:55

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
x = case items of
  [] -> []
  xs -> last xs
Code
foo [] = []
foo xs = 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