{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/15803","repository_url":"https://api.github.com/repos/JuliaLang/julia","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/15803/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/15803/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/15803/events","html_url":"https://github.com/JuliaLang/julia/issues/15803","id":146929337,"number":15803,"title":"add `Base.isunique`","user":{"login":"tpapp","id":84122,"avatar_url":"https://avatars.githubusercontent.com/u/84122?v=3","gravatar_id":"","url":"https://api.github.com/users/tpapp","html_url":"https://github.com/tpapp","followers_url":"https://api.github.com/users/tpapp/followers","following_url":"https://api.github.com/users/tpapp/following{/other_user}","gists_url":"https://api.github.com/users/tpapp/gists{/gist_id}","starred_url":"https://api.github.com/users/tpapp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tpapp/subscriptions","organizations_url":"https://api.github.com/users/tpapp/orgs","repos_url":"https://api.github.com/users/tpapp/repos","events_url":"https://api.github.com/users/tpapp/events{/privacy}","received_events_url":"https://api.github.com/users/tpapp/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":22,"created_at":"2016-04-08T13:27:24Z","updated_at":"2016-04-27T18:14:38Z","closed_at":null,"body":"A common idiom for testing if values in a collection `C` are unique is\r\n```julia\r\nlength(unique(C))==length(C)\r\n```\r\nor variations, eg when the length `n` is known,\r\n```julia\r\nlength(unique(C))==n\r\n```\r\nThese show up in various tests, assertions, inner constructors. However, if the goal is only to test for uniqueness, not to obtain a list of unique elements, then something like\r\n```julia\r\nfunction isunique(C)\r\n    seen = Set{eltype(C)}()\r\n    for x in C\r\n        if in(x, seen)\r\n            return false\r\n        else\r\n            push!(seen, x)\r\n        end\r\n    end\r\n    true\r\nend\r\n```\r\nis much more efficient: it can terminate early and avoids the construction of the intermediate array. Also, programmer's the intent is more clear.\r\n\r\nI am of course reluctant to suggest adding functions to `Base`, but it would good to have `unique` and `isunique` in the same module."},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/215178624","html_url":"https://github.com/JuliaLang/julia/issues/15803#issuecomment-215178624","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/15803","id":215178624,"user":{"login":"StefanKarpinski","id":153596,"avatar_url":"https://avatars.githubusercontent.com/u/153596?v=3","gravatar_id":"","url":"https://api.github.com/users/StefanKarpinski","html_url":"https://github.com/StefanKarpinski","followers_url":"https://api.github.com/users/StefanKarpinski/followers","following_url":"https://api.github.com/users/StefanKarpinski/following{/other_user}","gists_url":"https://api.github.com/users/StefanKarpinski/gists{/gist_id}","starred_url":"https://api.github.com/users/StefanKarpinski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StefanKarpinski/subscriptions","organizations_url":"https://api.github.com/users/StefanKarpinski/orgs","repos_url":"https://api.github.com/users/StefanKarpinski/repos","events_url":"https://api.github.com/users/StefanKarpinski/events{/privacy}","received_events_url":"https://api.github.com/users/StefanKarpinski/received_events","type":"User","site_admin":false},"created_at":"2016-04-27T18:14:38Z","updated_at":"2016-04-27T18:14:38Z","body":"+1 on `allunique`"}}