< 99 Elm Problems < Problem 14
Solution 1: Recursive version
duplicate list =
case list of
[] -> []
x :: xs -> x :: x :: duplicate xs
Solution 2: Pointfree, using List.foldr
duplicate = List.foldr (\x xs -> x :: x :: xs) []
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.