Skip to content

Instantly share code, notes, and snippets.

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