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) Float64In this example, the
typejoinfunction returnsFloat64as the resulting type that can accommodate bothIntandFloat64. -
Joining two array types:
julia> typejoin(Vector{Int}, Vector{Float64}) Array{Float64,1}Here, the
typejoinfunction 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
typejoinfunction returnsUnion{Bar, Foo}which is the most general type that includes bothFooandBar.
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.