99 Elm Problems/Problem 1

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

The Challenge[edit | edit source]

Find the last element of a list.

Test application[edit | edit source]

Implement lastElement in this test application.

module Main exposing (..)

import Html exposing (text)
import List
import Maybe

lastElement : List a -> Maybe a
lastElement list = 
  -- your implementation goes here
  Nothing

main =
  case lastElement [1,2,3,4] of
    Just a -> text (toString a)
    Nothing -> text "No element found"

Expected Result[edit | edit source]

4

Solutions