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

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"

Result:

4

Solutions