typejoin(T, S)

Compute a type that contains both T and S.


julia> typejoin(Int, Float64)

julia> typejoin(Vector{Int}, Vector{Float64})

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:

  1. Joining two primitive types:

    julia> typejoin(Int, Float64)

    In this example, the typejoin function returns Float64 as the resulting type that can accommodate both Int and Float64.

  2. Joining two array types:

    julia> typejoin(Vector{Int}, Vector{Float64})

    Here, the typejoin function computes the type Array{Float64,1} as the most general type that can hold both Vector{Int} and Vector{Float64}.

  3. Joining custom types:
    julia> struct Foo end
    julia> struct Bar end
    julia> typejoin(Foo, Bar)
    Union{Bar, Foo}

    In this example, the typejoin function returns Union{Bar, Foo} which is the most general type that includes both Foo and Bar.

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.

*Required Field

Checking you are not a robot: