Types
TODO
Missing
Nothing
Temp docs
Core.typeof
— Functiontypeof(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
— Functionsupertype(T::DataType)
Return the supertype of DataType T
.
Examples
julia> supertype(Int32)
Signed
Base.widen
— Functionwiden(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.5
Core.isa
— Functionisa(x, type) -> Bool
Determine whether x
is of the given type
. Can also be used as an infix operator, e.g. x isa type
.
Examples
julia> isa(1, Int)
true
julia> isa(1, Matrix)
false
julia> isa(1, Char)
false
julia> isa(1, Number)
true
julia> 1 isa Number
true
Core.:<:
— Function<:(T1, T2)
Subtype operator: returns true
if and only if all values of type T1
are also of type T2
.
Examples
julia> Float64 <: AbstractFloat
true
julia> Vector{Int} <: AbstractArray
true
julia> Matrix{Float64} <: Matrix{AbstractFloat}
false
Base.:>:
— Function>:(T1, T2)
Supertype operator, equivalent to T2 <: T1
.
Base.isbits
— Functionisbits(x)
Return true
if x
is an instance of an isbitstype
type.
Base.isconcretetype
— Functionisconcretetype(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})
false
Base.isabstracttype
— Functionisabstracttype(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)
false
Base.issingletontype
— FunctionBase.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
— Functionisinteger(x) -> Bool
Test whether x
is numerically equal to some integer.
Examples
julia> isinteger(4.0)
true
Base.typemax
— Functiontypemax(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.4028235f38
Base.typemin
— Functiontypemin(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.4028235f38
Base.floatmax
— Functionfloatmax(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)
Inf
Base.Missing
— TypeMissing
A type with no fields whose singleton instance missing
is used to represent missing values.
See also: skipmissing
, nonmissingtype
, Nothing
.
Base.ismissing
— FunctionBase.skipmissing
— Functionskipmissing(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
2
Base.nonmissingtype
— Functionnonmissingtype(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)
Any
This function is exported as of Julia 1.3.
Core.Nothing
— TypeBase.isnothing
— Functionisnothing(x)
Return true
if x === nothing
, and return false
if not.
This function requires at least Julia 1.1.
See also something
, Base.notnothing
, ismissing
.
Base.notnothing
— Functionnotnothing(x)
Throw an error if x === nothing
, and return x
if not.
Base.Some
— TypeSome{T}
A wrapper type used in Union{Some{T}, Nothing}
to distinguish between the absence of a value (nothing
) and the presence of a nothing
value (i.e. Some(nothing)
).
Use something
to access the value wrapped by a Some
object.
Base.something
— Functionsomething(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 present
Base.@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
This macro is available as of Julia 1.7.