Traits

Comparing Static, Mutable, and Immutable Types

The difference between each type of range is conceptualized as "static", "fixed", or "dynamic".

StaticRanges.as_dynamicFunction
as_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)
source
StaticRanges.as_staticFunction
as_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)
source
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.

source
StaticRanges.as_fixedFunction
as_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.0
source

Order 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_forwardFunction
is_forward(x) -> Bool

Returns 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)
false
source
StaticRanges.is_reverseFunction
is_reverse(x) -> Bool

Returns 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)
true
source
StaticRanges.is_orderedFunction
is_ordered(x) -> Bool

Returns 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).

source
StaticRanges.is_beforeFunction
is_before(x::T, y::T, collection::AbstractVector{T}) -> Bool

Returns true if x is before y in collection.

source
is_before(x::AbstractVector{T}, y::AbstractVector{T}) -> is_before(order(x), order(y), x, y)
is_before(::Ordering, ::Ordering, x, y) -> Bool

Returns 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)
true
source
StaticRanges.is_afterFunction
is_after(x::T, y::T, collection::AbstractVector{T}) -> Bool

Returns true if x is after y in collection.

source
is_after(x::AbstractVector{T}, y::AbstractVector{T}) -> is_after(order(x), order(y), x, y)
is_after(::Ordering, ::Ordering, x, y) -> Bool

Returns 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)
false
source
StaticRanges.is_contiguousFunction
is_contiguous(x, y) = is_contiguous(order(x), order(y), x, y)
is_contiguous(::Ordering, ::Ordering, x, y) -> Bool

Returns 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)
false
source

Other Traits

Missing docstring.

Missing docstring for StaticRanges.axes_type. Check Documenter's build log for details.