Public API

WhereTraits

There are also some helpers:

WhereTraits.BasicTraits

WhereTraits.BasicTraits.@overwrite_BaseMacro
WhereTraits.BasicTraits.@overwrite_Base

Overloading functions already defined in base, so that they work similar to Base.eltype in that they are best defined on Types, with a fallback from values which just grabs the type of the value and tries it again.

The following functions are currently over-defined:

  • isimmutable
  • ismutable
  • isbitstype
  • isconcretetype

In addition, also using WhereTraits.BasicTraits is run.

source
WhereTraits.BasicTraits.iscallableFunction
callable(T) -> Bool

Checks whether the call-syntax is defined for the given Type. For convenience iscallable(value) = iscallable(typeof(value))

Examples

julia> using WhereTraits; WhereTraits.BasicTraits.@overwrite_Base

julia> iscallable(typeof(+))
true

julia> iscallable(+)
true

julia> iscallable(Some)
false

julia> iscallable(typeof(Some))
true
source
WhereTraits.BasicTraits.isiterableFunction
isiterable(T) -> Bool

Test if type T is an iterable collection type or not, that is whether it has an iterate method or not.

When given a value instead of a Type, it fallbacks to use typeof(value).

source
WhereTraits.BasicTraits.isimmutableFunction
isimmutable(v) -> Bool

Return true iff value v is immutable. Note that this function works on Types instead of values (oppositely to Base.isimmutable). When applied to a value, a default clause will match on its type instead.

Examples

julia> using WhereTraits; WhereTraits.BasicTraits.@overwrite_Base

julia> isimmutable(1)
true

julia> isimmutable([1,2])
false
source
WhereTraits.BasicTraits.ismutableFunction
ismutable(v) -> Bool

Return true iff value v is mutable. Note that this function works on Types instead of values (oppositely to Base.isimmutable). When applied to a value, a default clause will match on its type instead.

Examples

julia> using WhereTraits; WhereTraits.BasicTraits.@overwrite_Base

julia> ismutable(1)
false

julia> ismutable([1,2])
true
source
WhereTraits.BasicTraits.isconcretetypeFunction
isconcretetype(T)

Determine whether type T is a concrete type, meaning it could have direct instances (values x such that typeof(x) === T).

For convenience isconcretetype(value) = isconcretetype(typeof(value))

Examples

julia> using WhereTraits; WhereTraits.BasicTraits.@overwrite_Base

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

julia> isconcretetype([1,2,3])
true

julia> isconcretetype("hi")
true
source
WhereTraits.BasicTraits.isbitstypeFunction
isbitstype(T)

Return true if type T is a "plain data" type, meaning it is immutable and contains no references to other values, only primitive types and other isbitstype types. Typical examples are numeric types such as UInt8, Float64, and Complex{Float64}. This category of types is significant since they are valid as type parameters, may not track isdefined / isassigned status, and have a defined layout that is compatible with C.

For convenience isbitstype(value) = isbitstype(typeof(value))

Examples

julia> using WhereTraits; WhereTraits.BasicTraits.@overwrite_Base

julia> isbitstype(Complex{Float64})
true

julia> isbitstype(Complex)
false

julia> isbitstype(1)
true
source