diff --git a/examples/typetree.jl b/examples/typetree.jl new file mode 100644 index 0000000..54844a4 --- /dev/null +++ b/examples/typetree.jl @@ -0,0 +1,24 @@ +# DataType +function AbstractTrees.children(t::Type) + t === Function ? Vector{Type}() : filter!(x -> x !== Any,subtypes(t)) +end +AbstractTrees.printnode(io::IO,t::Type) = print(io,t) + +print_tree(IO) + +println() + +print_tree(Real) + +println() + +# Dict +AbstractTrees.children(d::Dict) = [p for p in d] +AbstractTrees.children(p::Pair) = AbstractTrees.children(p[2]) +function AbstractTrees.printnode(io::IO,p::Pair) + isempty(AbstractTrees.children(p[2])) ? print(io,"$(p[1]): $(p[2])") : print(io,"$(p[1]):") +end + +d = Dict(:a => 2,:d => Dict(:b => 4,:c => "Hello"),:e => 5.0) + +print_tree(d) \ No newline at end of file