# \#union

**URL:** https://discourse.julialang.org/tag/union/1162.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [\[ANN\]: WrappedUnions.jl: Wrap a Union for enhanced type-stability](https://discourse.julialang.org/t/ann-wrappedunions-jl-wrap-a-union-for-enhanced-type-stability/132322)

<div class="topic-metadata">

**Author:** [@Tortar](https://discourse.julialang.org/u/Tortar)\
**Replies:** 11\
**Last updated:** [March 24, 2026, 12:32pm UTC](https://discourse.julialang.org/t/ann-wrappedunions-jl-wrap-a-union-for-enhanced-type-stability/132322 "2026-03-24T12:32:39Z")

</div>

Hi all, I’d like to announce the package WrappedUnions.jl. This package originates by my better understanding of type instabilities caused by using union of types and offers a better interface than my previous attempt L…

---

## [\`Tuple\` of \`Union\` or \`Union\` of \`Tuple\`?](https://discourse.julialang.org/t/tuple-of-union-or-union-of-tuple/134311)

<div class="topic-metadata">

**Author:** [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Replies:** 8\
**Last updated:** [December 4, 2025, 10:28am UTC](https://discourse.julialang.org/t/tuple-of-union-or-union-of-tuple/134311 "2025-12-04T10:28:12Z")

</div>

I want to annotate a type-unstable variable with a type-parameter constraint to improve the chance of union splitting during compilation. In general, should I do Tuple of Union or Union of Tuple? For example, which of t…

---

## [Coupling finite\`Union\` with \`T\` in \`NTuple{2, T} where {T}\`](https://discourse.julialang.org/t/coupling-finite-union-with-t-in-ntuple-2-t-where-t/133567)

<div class="topic-metadata">

**Author:** [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Replies:** 7\
**Last updated:** [November 11, 2025, 10:48am UTC](https://discourse.julialang.org/t/coupling-finite-union-with-t-in-ntuple-2-t-where-t/133567 "2025-11-11T10:48:15Z")

</div>

We know that for UnionAll of Tuple that uses the same type parameter (e.g., T) for all the element types (in default) requires the element types to be the same concrete type: julia\> f1(a::Tuple{T, T}) where {T\<:Real} = …

---

## [What type union (\`Union\`) is equivalent to an iterated union (\`UnionAll\`) with a concrete type bound?](https://discourse.julialang.org/t/what-type-union-union-is-equivalent-to-an-iterated-union-unionall-with-a-concrete-type-bound/132140)

<div class="topic-metadata">

**Author:** [@Benny](https://discourse.julialang.org/u/Benny)\
**Replies:** 5\
**Last updated:** [September 7, 2025, 5:32pm UTC](https://discourse.julialang.org/t/what-type-union-union-is-equivalent-to-an-iterated-union-unionall-with-a-concrete-type-bound/132140 "2025-09-07T17:32:40Z")

</div>

As far as I know and have read, the only subtypes of a concrete type that isn’t DataType are itself and the bottom type Union{}. However, that doesn’t seem to be the case as type parameters: julia\> let T = Vector, P = I…

---

## [Abusing \`convert\` as an alternative to \`Union{Nothing, Int64}\`](https://discourse.julialang.org/t/abusing-convert-as-an-alternative-to-union-nothing-int64/131534)

<div class="topic-metadata">

**Author:** [@nhz2](https://discourse.julialang.org/u/nhz2)\
**Replies:** 15\
**Last updated:** [August 19, 2025, 8:14pm UTC](https://discourse.julialang.org/t/abusing-convert-as-an-alternative-to-union-nothing-int64/131534 "2025-08-19T20:14:52Z")

</div>

In C it is common to have functions that return a positive integer result on success, or a negative integer if an error happens. When I use these functions, I tend to forget the possible error values and do integer arith…

---

## [Can the overhead of \`myT{\<:T}\` compared to \`myT{T}\`, where \`T\` is a concrete type, be avoided?](https://discourse.julialang.org/t/can-the-overhead-of-myt-t-compared-to-myt-t-where-t-is-a-concrete-type-be-avoided/122721)

<div class="topic-metadata">

**Author:** [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Replies:** 3\
**Last updated:** [November 17, 2024, 11:05am UTC](https://discourse.julialang.org/t/can-the-overhead-of-myt-t-compared-to-myt-t-where-t-is-a-concrete-type-be-avoided/122721 "2024-11-17T11:05:17Z")

</div>

I understand that Vector{\<:Float64} is not the same as Vector{Float64} as it allows the bottom type Union{} to be its element type and is (therefore) not a concrete type: julia\> Vector{Union{}} \<: Vector{\<:Float64} true…

---

## [Parametric Types with Union](https://discourse.julialang.org/t/parametric-types-with-union/121507)

<div class="topic-metadata">

**Author:** [@danrib07](https://discourse.julialang.org/u/danrib07)\
**Replies:** 2\
**Last updated:** [October 21, 2024, 1:42pm UTC](https://discourse.julialang.org/t/parametric-types-with-union/121507 "2024-10-21T13:42:45Z")

</div>

I have the following snippet: abstract type AbstractReaction end abstract type AbstractSpecies end abstract type AbstractRateLaw end struct Species \<: AbstractSpecies name::Union{AbstractString,Symbol} end struct …

---

## [Understanding Types Union{}](https://discourse.julialang.org/t/understanding-types-union/103466)

<div class="topic-metadata">

**Author:** [@Denis\_Ivanov](https://discourse.julialang.org/u/Denis_Ivanov)\
**Replies:** 3\
**Last updated:** [September 2, 2023, 9:24pm UTC](https://discourse.julialang.org/t/understanding-types-union/103466 "2023-09-02T21:24:54Z")

</div>

I read the manual about types carefully, but I can’t figure out how to do this. Let’s two types of data are possible: Vector{Int8} and Vector{Vector{Int8}} eg \[1, 0, 1\] and \[\[1, 1\], \[0\]\] Following the recommendations,…

---

## [Function with vector of Union-Type](https://discourse.julialang.org/t/function-with-vector-of-union-type/88850)

<div class="topic-metadata">

**Author:** [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Replies:** 4\
**Last updated:** [October 17, 2022, 3:43pm UTC](https://discourse.julialang.org/t/function-with-vector-of-union-type/88850 "2022-10-17T15:43:57Z")

</div>

This does work: function \_foo1(\_range::AbstractVector=\[1,2\]) println(\_range) end \_foo1(\[1, missing\]) This fails: function \_foo2(\_range::Vector{Union{\<:Number, Missing}}=\[1, 2\]) println(\_range) end \_foo2(\[1, m…
