Skip to content

Instantly share code, notes, and snippets.

@maticzav
Last active January 23, 2017 10:55
Show Gist options
  • Save maticzav/bb50da59db9cd005969098a5f206a51b to your computer and use it in GitHub Desktop.
Save maticzav/bb50da59db9cd005969098a5f206a51b to your computer and use it in GitHub Desktop.
Elm - get only one element of value from list
unique : List a -> List a
unique list =
case list of
[] ->
[]
x :: [] ->
x :: []
x :: xs ->
if List.member x xs then
unique xs
else
x :: unique xs
-- unique [1,2,3,3,3,3] -> [1,2,3]
@maticzav
Copy link
Author

You can also do it shorter

getUnique : List comparable -> List comparable 
getUnique =
  Set.toList << Set.fromList

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment