Traits
Comparing Static, Mutable, and Immutable Types
The difference between each type of range is conceptualized as "static", "fixed", or "dynamic".
StaticRanges.is_static — Functionis_static(x) -> BoolReturns true if x is static.
StaticRanges.is_fixed — Functionis_fixed(x) -> BoolReturns true if the size of x is fixed.
StaticRanges.as_dynamic — Functionas_dynamic(x)If x is mutable then returns x, otherwise returns a comparable but mutable type to x.
Examples
julia> using StaticRanges
julia> as_dynamic(Base.OneTo(10))
OneToMRange(10)
julia> as_dynamic(UnitRange(1, 10))
UnitMRange(1:10)
julia> as_dynamic(StepRange(1, 2, 20))
StepMRange(1:2:19)
julia> as_dynamic(range(1.0, step=2.0, stop=20.0))
StepMRangeLen(1.0:2.0:19.0)
julia> as_dynamic(LinRange(1, 20, 10))
LinMRange(1.0, stop=20.0, length=10)StaticRanges.as_static — Functionas_static(x)If x is static then returns x, otherwise returns a comparable but static size type to x.
Examples
julia> using StaticRanges, StaticArrays
julia> as_static(Base.OneTo(10))
OneToSRange(10)
julia> as_static(UnitRange(2, 10))
UnitSRange(2:10)
julia> as_static(StepRange(1, 2, 20))
StepSRange(1:2:19)
julia> as_static(range(1.0, step=2.0, stop=20.0))
StepSRangeLen(1.0:2.0:19.0)
julia> as_static(LinRange(1, 20, 10))
LinSRange(1.0, stop=20.0, length=10)
as_static(x::AbstractArray[, hint::Val{S}])If x is static then returns x, otherwise returns a comparable but static size type to x. hint provides the option of passing along a statically defined tuple representing the size S of x.
StaticRanges.as_fixed — Functionas_fixed(x)If x is immutable then returns x, otherwise returns a comparable but fixed size type to x.
Examples
julia> using StaticRanges
julia> as_fixed(OneToMRange(10))
Base.OneTo(10)
julia> as_fixed(UnitMRange(1, 10))
1:10
julia> as_fixed(StepMRange(1, 2, 20))
1:2:19
julia> as_fixed(mrange(1.0, step=2.0, stop=20.0))
1.0:2.0:19.0
julia> as_fixed(LinMRange(1, 20, 10))
10-element LinRange{Float64}:
1.0,3.11111,5.22222,7.33333,9.44444,11.5556,13.6667,15.7778,17.8889,20.0Order traits
The following traits are used to conveniently characterize the order of ranges. They are not exported and are primarily intended for internal use.
StaticRanges.is_forward — Functionis_forward(x) -> BoolReturns true if x is sorted forward.
Examples
julia> using StaticRanges
julia> fr = 1:2:10
1:2:9
julia> rr = 10:-2:1
10:-2:2
julia> StaticRanges.is_forward(fr)
true
julia> StaticRanges.is_forward(rr)
falseStaticRanges.is_reverse — Functionis_reverse(x) -> BoolReturns true if x is sorted in reverse.
Examples
julia> using StaticRanges
julia> fr = 1:2:10
1:2:9
julia> rr = 10:-2:1
10:-2:2
julia> StaticRanges.is_reverse(fr)
false
julia> StaticRanges.is_reverse(rr)
trueStaticRanges.order — Functionorder(x) -> OrderingReturns the ordering of x.
StaticRanges.is_ordered — Functionis_ordered(x) -> BoolReturns true if x is ordered. is_ordered should return the same value that issorted would on x except it doesn't specify how it's sorted (e.g., forward, reverse, etc).
StaticRanges.is_before — Functionis_before(x::T, y::T, collection::AbstractVector{T}) -> BoolReturns true if x is before y in collection.
is_before(x::AbstractVector{T}, y::AbstractVector{T}) -> is_before(order(x), order(y), x, y)
is_before(::Ordering, ::Ordering, x, y) -> BoolReturns true if all elements in x are before all elements in y. Functionally equivalent to all(x .< y).
Examples
julia> using StaticRanges
julia> r1 = 1:5
1:5
julia> r2 = 6:10
6:10
julia> StaticRanges.is_before(r2, r1)
false
julia> StaticRanges.is_before(r1, r2)
trueStaticRanges.is_after — Functionis_after(x::T, y::T, collection::AbstractVector{T}) -> BoolReturns true if x is after y in collection.
is_after(x::AbstractVector{T}, y::AbstractVector{T}) -> is_after(order(x), order(y), x, y)
is_after(::Ordering, ::Ordering, x, y) -> BoolReturns true if all elements in x are after all elements in y. Functionally equivalent to all(x .> y).
Examples
julia> using StaticRanges
julia> r1 = 1:5
1:5
julia> r2 = 6:10
6:10
julia> StaticRanges.is_after(r2, r1)
true
julia> StaticRanges.is_after(r1, r2)
falseStaticRanges.is_contiguous — Functionis_contiguous(x, y) = is_contiguous(order(x), order(y), x, y)
is_contiguous(::Ordering, ::Ordering, x, y) -> BoolReturns true if one of the ends of x may be extended by a single overlapping end of y.
Example
julia> using StaticRanges
julia> StaticRanges.is_contiguous(1:3, 3:4)
true
julia> StaticRanges.is_contiguous(3:-1:1, 3:4)
true
julia> StaticRanges.is_contiguous(3:-1:1, 4:-1:3)
true
julia> StaticRanges.is_contiguous(1:3, 4:-1:3)
true
julia> StaticRanges.is_contiguous(1:3, 2:4)
falseOther Traits
Missing docstring for StaticRanges.axes_type. Check Documenter's build log for details.