Skip to content

Instantly share code, notes, and snippets.

@Datseris
Created September 7, 2018 15:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Datseris/1b1aa1287041cab1b2dff306ddc4f899 to your computer and use it in GitHub Desktop.
Save Datseris/1b1aa1287041cab1b2dff306ddc4f899 to your computer and use it in GitHub Desktop.
get all concrete subtypes of a Julia abstract type
julia> function _subtypes(type::Type)
out = Any[]
_subtypes!(out, type)
end
_subtypes (generic function with 1 method)
julia> function _subtypes!(out, type::Type)
if !isabstracttype(type)
push!(out, type)
else
foreach(T->_subtypes!(out, T), subtypes(type))
end
out
end
_subtypes! (generic function with 1 method)
julia> _subtypes(Number)
19-element Array{Any,1}:
Complex
BigFloat
Float16
Float32
Float64
Irrational
Bool
BigInt
Int128
Int16
Int32
Int64
Int8
UInt128
UInt16
UInt32
UInt64
UInt8
Rational
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment