99 Elm Problems/Problem 2

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

Problem 2: Implement the function penultimate to find the next to last element of a list.

import Html exposing (text)
import List
import Maybe

penultimate : List a -> Maybe a
-- your implementation goes here
main =
  case penultimate (List.range 1 4) of
    Just a -> text (toString a)
    Nothing -> text "No element found"