What is Base.KeySet()?

The documentation for keys describe it a bit although it doesn’t mention KeySet explicitly:

help?> keys

    keys(a::AbstractDict)

Return an iterator over all keys in a dictionary. [...]

And to be more explicit, KeySet is one such iterator which yields the keys of the dictionary when iterated. It is simply a “lazy-view” of the keys (see https://github.com/JuliaLang/julia/blob/10b0a014275ad4836fad8d2a2590d457dc2286ad/base/abstractdict.jl#L39-L41) and it is implemented like this (presumably) for efficiency since you don’t have to materialize an array or similar with all the keys.

4 Likes