Skip to content

Instantly share code, notes, and snippets.

@laborg
laborg / gist:f9af0f5c2def4edfa410c5522afbff1d
Created Sep 10, 2018
Explicit implementation of uniquifying algorithms
View gist:f9af0f5c2def4edfa410c5522afbff1d
# 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)