Types
TODO
Missing
Nothing
Temp docs
Core.typeof — Function
typeof(x)Get the concrete type of x.
See also eltype.
Examples
julia> a = 1//2;
julia> typeof(a)
Rational{Int64}
julia> M = [1 2; 3.5 4];
julia> typeof(M)
Matrix{Float64} (alias for Array{Float64, 2})Base.supertype — Function
supertype(T::Union{DataType, UnionAll})Return the direct supertype of type T. T can be a DataType or a UnionAll type. Does not support type Unions. Also see info on Types.
Examples
julia> supertype(Int32)
Signed
julia> supertype(Vector)
DenseVector (alias for DenseArray{T, 1} where T)Base.widen — Function
widen(x)If x is a type, return a "larger" type, defined so that arithmetic operations + and - are guaranteed not to overflow nor lose precision for any combination of values that type x can hold.
For fixed-size integer types less than 128 bits, widen will return a type with twice the number of bits.
If x is a value, it is converted to widen(typeof(x)).
Examples
julia> widen(Int32)
Int64
julia> widen(1.5f0)
1.5Core.:<: — Function
<:(T1, T2)::BoolSubtyping relation, defined between two types. In Julia, a type S is said to be a subtype of a type T if and only if we have S <: T.
For any type L and any type R, L <: R implies that any value v of type L is also of type R. I.e., (L <: R) && (v isa L) implies v isa R.
The subtyping relation is a partial order. I.e., <: is:
reflexive: for any type
T,T <: Tholdsantisymmetric: for any type
Aand any typeB,(A <: B) && (B <: A)impliesA == Btransitive: for any type
A, any typeBand any typeC;(A <: B) && (B <: C)impliesA <: C
See also info on Types, Union{}, Any, isa.
Examples
julia> Float64 <: AbstractFloat
true
julia> Vector{Int} <: AbstractArray
true
julia> Matrix{Float64} <: Matrix{AbstractFloat} # `Matrix` is invariant
false
julia> Tuple{Float64} <: Tuple{AbstractFloat} # `Tuple` is covariant
true
julia> Union{} <: Int # The bottom type, `Union{}`, subtypes each type.
true
julia> Union{} <: Float32 <: AbstractFloat <: Real <: Number <: Any # Operator chaining
trueThe <: keyword also has several syntactic uses which represent the same subtyping relation, but which do not execute the operator or return a Bool:
To specify the lower bound and the upper bound on a parameter of a
UnionAlltype in awherestatement.To specify the lower bound and the upper bound on a (static) parameter of a method, see Parametric Methods.
To define a subtyping relation while declaring a new type, see
structandabstract type.
Base.isbits — Function
isbits(x)Return true if x is an instance of an isbitstype type.
Base.isconcretetype — Function
isconcretetype(T)Determine whether type T is a concrete type, meaning it could have direct instances (values x such that typeof(x) === T). Note that this is not the negation of isabstracttype(T). If T is not a type, then return false.
See also: isbits, isabstracttype, issingletontype.
Examples
julia> isconcretetype(Complex)
false
julia> isconcretetype(Complex{Float32})
true
julia> isconcretetype(Vector{Complex})
true
julia> isconcretetype(Vector{Complex{Float32}})
true
julia> isconcretetype(Union{})
false
julia> isconcretetype(Union{Int,String})
falseBase.isabstracttype — Function
isabstracttype(T)Determine whether type T was declared as an abstract type (i.e. using the abstract type syntax). Note that this is not the negation of isconcretetype(T). If T is not a type, then return false.
Examples
julia> isabstracttype(AbstractArray)
true
julia> isabstracttype(Vector)
falseBase.issingletontype — Function
Base.issingletontype(T)Determine whether type T has exactly one possible instance; for example, a struct type with no fields except other singleton values. If T is not a concrete type, then return false.
Base.isinteger — Function
isinteger(x) -> BoolTest whether x is numerically equal to some integer.
Examples
julia> isinteger(4.0)
trueBase.typemax — Function
typemax(T)The highest value representable by the given (real) numeric DataType.
See also: floatmax, typemin, eps.
Examples
julia> typemax(Int8)
127
julia> typemax(UInt32)
0xffffffff
julia> typemax(Float64)
Inf
julia> typemax(Float32)
Inf32
julia> floatmax(Float32) # largest finite Float32 floating point number
3.4028235f38Base.typemin — Function
typemin(T)The lowest value representable by the given (real) numeric DataType T.
See also: floatmin, typemax, eps.
Examples
julia> typemin(Int8)
-128
julia> typemin(UInt32)
0x00000000
julia> typemin(Float16)
-Inf16
julia> typemin(Float32)
-Inf32
julia> nextfloat(-Inf32) # smallest finite Float32 floating point number
-3.4028235f38Base.floatmax — Function
floatmax(T = Float64)Return the largest finite number representable by the floating-point type T.
See also: typemax, floatmin, eps.
Examples
julia> floatmax(Float16)
Float16(6.55e4)
julia> floatmax(Float32)
3.4028235f38
julia> floatmax()
1.7976931348623157e308
julia> typemax(Float64)
InfBase.Missing — Type
MissingA type with no fields whose singleton instance missing is used to represent missing values.
See also: skipmissing, nonmissingtype, Nothing.
Base.ismissing — Function
Base.skipmissing — Function
skipmissing(itr)Return an iterator over the elements in itr skipping missing values. The returned object can be indexed using indices of itr if the latter is indexable. Indices corresponding to missing values are not valid: they are skipped by keys and eachindex, and a MissingException is thrown when trying to use them.
Use collect to obtain an Array containing the non-missing values in itr. Note that even if itr is a multidimensional array, the result will always be a Vector since it is not possible to remove missings while preserving dimensions of the input.
See also coalesce, ismissing, something.
Examples
julia> x = skipmissing([1, missing, 2])
skipmissing(Union{Missing, Int64}[1, missing, 2])
julia> sum(x)
3
julia> x[1]
1
julia> x[2]
ERROR: MissingException: the value at index (2,) is missing
[...]
julia> argmax(x)
3
julia> collect(keys(x))
2-element Vector{Int64}:
1
3
julia> collect(skipmissing([1, missing, 2]))
2-element Vector{Int64}:
1
2
julia> collect(skipmissing([1 missing; 2 missing]))
2-element Vector{Int64}:
1
2Base.nonmissingtype — Function
nonmissingtype(T::Type)If T is a union of types containing Missing, return a new type with Missing removed.
Examples
julia> nonmissingtype(Union{Int64,Missing})
Int64
julia> nonmissingtype(Any)
AnyBase.isnothing — Function
isnothing(x)Return true if x === nothing, and return false if not.
See also something, Base.notnothing, ismissing.
Base.notnothing — Function
notnothing(x)Throw an error if x === nothing, and return x if not.
Base.something — Function
something(x...)Return the first value in the arguments which is not equal to nothing, if any. Otherwise throw an error. Arguments of type Some are unwrapped.
See also coalesce, skipmissing, @something.
Examples
julia> something(nothing, 1)
1
julia> something(Some(1), nothing)
1
julia> something(Some(nothing), 2) === nothing
true
julia> something(missing, nothing)
missing
julia> something(nothing, nothing)
ERROR: ArgumentError: No value arguments presentBase.@something — Macro
@something(x...)Short-circuiting version of something.
Examples
julia> f(x) = (println("f($x)"); nothing);
julia> a = 1;
julia> a = @something a f(2) f(3) error("Unable to find default for `a`")
1
julia> b = nothing;
julia> b = @something b f(2) f(3) error("Unable to find default for `b`")
f(2)
f(3)
ERROR: Unable to find default for `b`
[...]
julia> b = @something b f(2) f(3) Some(nothing)
f(2)
f(3)
julia> b === nothing
true