Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@oxinabox
Created September 28, 2020 12:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oxinabox/b560457bacd9129248aa483488dc8943 to your computer and use it in GitHub Desktop.
Save oxinabox/b560457bacd9129248aa483488dc8943 to your computer and use it in GitHub Desktop.
Decomposes til isbits
function print_isbits(f)
seen = Set()
MAX_ELE = 3
function print_isbits(fname, fval::FTYPE, indent) where FTYPE
ftext = "$fname - $FTYPE\n"
print(" "^indent)
fbits = isbitstype(FTYPE)
if fbits
printstyled("✔ $ftext"; color=:green)
else
printstyled("✘ $ftext"; color=:red)
if fval ∉ seen
push!(seen, fval)
print_isbits_children(fval, indent+1)
else
print(" "^indent)
printstyled(" ⤴⤴⤴\n"; color=:blue)
end
end
end
function print_isbits_children(fval::Vector, indent)
isempty(fval) && return nothing
if !isabstracttype(eltype(fval))
# concrete eltype means don't need to break it down
print_isbits("elements", first(fval), indent)
else
for (ii, cval) in enumerate(fval[1:min(end, MAX_ELE)])
print_isbits("$ii", cval, indent)
end
if length(fval) > MAX_ELE
print(" "^indent)
printstyled("... ...\n"; color=:blue)
end
end
end
function print_isbits_children(fval::AbstractDict, indent)
# redispatch to used vector display
print(" "^indent)
printstyled("keys:\n"; color=:blue)
print_isbits_children(collect(keys(fval)), indent)
print(" "^indent)
printstyled("values:\n"; color=:blue)
print_isbits_children(collect(values(fval)), indent)
end
function print_isbits_children(fval::FTYPE, indent) where FTYPE
isabstracttype(FTYPE) && return nothing
for child_name in fieldnames(FTYPE)
child_value = getfield(fval, child_name)
print_isbits(child_name, child_value, indent)
end
end
# Don't try and break down internals of types
print_isbits_children(fval::Type, indent) = nothing
print_isbits("🌸", f, 0)
end
@oxinabox
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment