< 99 Elm Problems < Problem 8

Solution 1: Recursive version

compress list =
  case list of
    [] -> []
    [ first ] -> [ first ]
    first :: next :: tail ->
      if first == next then
        compress (next :: tail)
      else
        first :: compress (next :: tail)
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.