< 99 Elm Problems
Problem 3: Implement the function nth
to return the n-th element of a list.
import Html exposing (text)
import List exposing (head, length)
import Maybe
nth: Int -> List a -> Maybe a
-- your implementation goes here
main =
case (nth 2 (List.range 1 4)) of
Just a -> text (toString a)
Nothing -> text "No element found"
Result:
3
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.