99 Elm Problems/Lists Problem 1/Find the last element of a list

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Find the last element of a list. Assume a non-empty list.

Example in Elm:

import Graphics.Element exposing (show)
import List
import Maybe

myLast : List a -> Maybe a

main =
  case myLast [1,2,3,4] of 
    Just a -> show a
    Nothing -> show "No element found"