Array printing of custom objects

One small bug is you need the println in the loop to print to io:

    for i ∈ keys(cs.dict) println(io, i) end

This will fix most of your issues.

You might also want to check if the IOContext has already printed type info so you can avoid having type info for each element of an array.

The spacing is also a little better with something like:

function Base.show(io::IO, ::MIME"text/plain", cs::CustomSet)
    print(io, "$(length(cs.dict))-element $(typeof(cs)):\n ")
    print(io, join(keys(cs.dict), "\n "))
end

The other IOContext elements are also useful for displaying very large sets in a REPL-friendly way.

3 Likes