< 99 Elm Problems < Problem 3
Solution 1: Recursive version
nth n list =
case (list, n) of
([], _) -> Nothing
(head :: _, 0) -> Just head
(_ :: tail, _) -> nth (n-1) tail
Solution 2: Point Free version
nth n =
drop n >> head
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.