Created
September 7, 2018 15:53
-
-
Save Datseris/1b1aa1287041cab1b2dff306ddc4f899 to your computer and use it in GitHub Desktop.
get all concrete subtypes of a Julia abstract type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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