typejoin
typejoin(T, S)
Compute a type that contains both T
and S
.
Examples
julia> typejoin(Int, Float64)
Float64
julia> typejoin(Vector{Int}, Vector{Float64})
Array{Float64,1}
The typejoin
function in Julia computes a type that contains both T
and S
. It returns the most general type that encompasses both T
and S
. Here are a few examples to illustrate its usage:
-
Joining two primitive types:
julia> typejoin(Int, Float64) Float64
In this example, the
typejoin
function returnsFloat64
as the resulting type that can accommodate bothInt
andFloat64
. -
Joining two array types:
julia> typejoin(Vector{Int}, Vector{Float64}) Array{Float64,1}
Here, the
typejoin
function computes the typeArray{Float64,1}
as the most general type that can hold bothVector{Int}
andVector{Float64}
. - Joining custom types:
julia> struct Foo end julia> struct Bar end julia> typejoin(Foo, Bar) Union{Bar, Foo}
In this example, the
typejoin
function returnsUnion{Bar, Foo}
which is the most general type that includes bothFoo
andBar
.
Note that the resulting joined type may be a Union type if the types being joined are not directly related.
Please make sure to provide valid types T
and S
to avoid errors when using typejoin
.
See Also
BigFloat, BigInt, Dict, eltype, fieldtype, Float32, Float64, IntSet, isa, isalnum, isalpha, isascii, iseltype, isequal, isgraph, isimmutable, isinteractive, isleaftype, isnull, ispunct, isspace, issubtype, keytype, Nullable, NullException, promote_type, typeintersect, typejoin, typemax, typemin, typeof, Val, valtype,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.