Skip to content

Commit

Permalink
improve Union docs as discused in discourse (#45109)
Browse files Browse the repository at this point in the history
Co-authored-by: Viral B. Shah <ViralBShah@users.noreply.github.com>
Co-authored-by: Daniel Karrasch <daniel.karrasch@posteo.de>
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
  • Loading branch information
4 people authored Oct 31, 2023
1 parent 2253cdf commit 5ae88f5
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions base/docs/basedocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2857,23 +2857,33 @@ kw"Union{}", Base.Bottom
"""
Union{Types...}
A type union is an abstract type which includes all instances of any of its argument types. The empty
union [`Union{}`](@ref) is the bottom type of Julia.
A `Union` type is an abstract type which includes all instances of any of its argument types.
This means that `T <: Union{T,S}` and `S <: Union{T,S}`.
Like other abstract types, it cannot be instantiated, even if all of its arguments are non
abstract.
# Examples
```jldoctest
julia> IntOrString = Union{Int,AbstractString}
Union{Int64, AbstractString}
julia> 1 isa IntOrString
julia> 1 isa IntOrString # instance of Int is included in the union
true
julia> "Hello!" isa IntOrString
julia> "Hello!" isa IntOrString # String is also included
true
julia> 1.0 isa IntOrString
julia> 1.0 isa IntOrString # Float64 is not included because it is neither Int nor AbstractString
false
```
# Extended Help
Unlike most other parametric types, unions are covariant in their parameters. For example,
`Union{Real, String}` is a subtype of `Union{Number, AbstractString}`.
The empty union [`Union{}`](@ref) is the bottom type of Julia.
"""
Union

Expand Down

2 comments on commit 5ae88f5

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package evaluation job you requested has completed - possible new issues were detected.
The full report is available.

Please sign in to comment.