View gist:f9af0f5c2def4edfa410c5522afbff1d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Implementation bodies for unique and unique! | |
function _unique(itr, f::Union{Nothing, Callable} = nothing) | |
T = @default_eltype(itr) | |
y = iterate(itr) | |
y === nothing && return T[] | |
x, st = y | |
R = !isconcretetype(T) && IteratorEltype(itr) == EltypeUnknown() ? typeof(x) : T | |
f === nothing && return __uniquify(itr, R[], Set{R}(), st, x) | |
fx = f(x) | |
return __uniquify(itr, R[], Set{typeof(fx)}(), st, x, f, fx) |