Public API
WhereTraits
WhereTraits.Syntax.@traits — Macro@traits f(a, b) where {!isempty(a), !isempty(b)} = (a[1], b[1])
WhereTraits.Syntax.@traits_order — Macro@traits_order AnotherModule.anotherfunc(a::T, b::T) where {T} begin isempty(a) isempty(b) end
There are also some helpers:
WhereTraits.ExtraHelpers.@traits_show_implementation — Macro@traits_show_implementation mytraitsenabled_functionRender a whole TraitsStore. To get an easy fealing of what is going on and inspect errors.
For debugging purposes only.
WhereTraits.ExtraHelpers.@traits_test — Macrolike @traits, and works within Test.@testset, but cannot be doc-stringed
needed because of https://github.com/JuliaLang/julia/issues/34263
WhereTraits.BasicTraits
WhereTraits.BasicTraits.@overwrite_Base — MacroWhereTraits.BasicTraits.@overwrite_BaseOverloading 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.
WhereTraits.BasicTraits.iscallable — Functioncallable(T) -> BoolChecks 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))
trueWhereTraits.BasicTraits.isiterable — Functionisiterable(T) -> BoolTest 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).
WhereTraits.BasicTraits.isimmutable — Functionisimmutable(v) -> BoolReturn 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])
falseWhereTraits.BasicTraits.ismutable — Functionismutable(v) -> BoolReturn 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])
trueWhereTraits.BasicTraits.isconcretetype — Functionisconcretetype(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")
trueWhereTraits.BasicTraits.isbitstype — Functionisbitstype(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