Range Types
There are static and mutable versions of most ranges present in the Base module of Julia. The basic terminology used herein is as follows:
- Static: fully parameterized through parametric typing (similar to how
Valis used) - Fixed: all parameters are immutable fields of a
struct. This is how all ranges inBaseare composed. - Dynamic: all parameters are mutable fields of a
struct. This is how a handful of ranges in this package are composed.
The vast majority of the time a fixed range is the appropriate choice. There are some situations (perhaps few) where alternatives may be extremely convenient. For example, a static range may be helpful when the exact same parameters are frequently being accessed and don't need to change (e.g., a component of a filter in a processing pipeline). Mutable ranges may be helpful when referring to a range that is accessed rarely but may change (e.g., descriptive parameters of a plot's axis). However, this package is intentionally built without many assumptions of how it should be used. For example, safe methods for mutating ranges without violating the same assumptions of their original construction are provided but access to their fields are not obfuscated beyond overloading the setproperty! method
Static Ranges
StaticRanges.OneToSRange — TypeOneToSRangeA static range that parallels OneTo in behavior.
StaticRanges.UnitSRange — TypeUnitSRangeA static range parameterized by a start and stop of type T, filled with elements spaced by 1 from start until stop is exceeded. The syntax a:b with a and b both Integers creates a UnitRange.
StaticRanges.LinSRange — TypeLinSRangeA static range with len linearly spaced elements between its start and stop. The size of the spacing is controlled by len, which must be an Int.
StaticRanges.StepSRange — TypeStepSRangeA static range with elements of type T with spacing of type S. The step between each element is constant, and the range is defined in terms of a start and stop of type T and a step of type S. Neither T nor S should be floating point types.
StaticRanges.StepSRangeLen — TypeStepSRangeLenA static range r where r[i] produces values of type T (in the second form, T is deduced automatically), parameterized by a reference value, a step, and the length. By default ref is the starting value r[1], but alternatively you can supply it as the value of r[offset] for some other index 1 <= offset <= len. In conjunction with TwicePrecision this can be used to implement ranges that are free of roundoff error.
Mutable Ranges
StaticRanges.OneToMRange — TypeOneToMRangeA mutable range that parallels OneTo in behavior.
StaticRanges.UnitMRange — TypeUnitMRangeA mutable range parameterized by a start and stop of type T, filled with elements spaced by 1 from start until stop is exceeded. The syntax a:b with a and b both Integers creates a UnitRange.
StaticRanges.LinMRange — TypeLinMRangeA mutable range with len linearly spaced elements between its start and stop. The size of the spacing is controlled by len, which must be an Int.
StaticRanges.StepMRange — TypeStepMRangeA mutable range with elements of type T with spacing of type S. The step between each element is constant, and the range is defined in terms of a start and stop of type T and a step of type S. Neither T nor S should be floating point types.
StaticRanges.StepMRangeLen — TypeStepMRangeLenA mutable range r where r[i] produces values of type T (in the second form, T is deduced automatically), parameterized by a reference value, a step, and the length. By default ref is the starting value r[1], but alternatively you can supply it as the value of r[offset] for some other index 1 <= offset <= len. In conjunction with TwicePrecision this can be used to implement ranges that are free of roundoff error.
Abstract Ranges
StaticRanges.OneToRange — TypeOneToRangeSupertype for OneToSRange and OneToMRange. It's subtypes should behave identically to Base.OneTo.
StaticRanges.AbstractLinRange — TypeAbstractLinRangeSupertype for mutable or static ranges with len linearly spaced elements between its start and stop.
StaticRanges.AbstractStepRangeLen — TypeAbstractStepRangeLenSupertype for StepSRangeLen and StepMRangeLen. It's subtypes should behave identically to StepRangeLen.
StaticRanges.AbstractStepRange — TypeAbstractStepRangeSupertype for StepSRange and StepMRange. It's subtypes should behave identically to StepRange.
Special Ranges
StaticRanges.GapRange — TypeGapRange{T,F,L}Represents a range that is broken up by gaps making it noncontinuous. This allows more compact storage of numbers where the majority are known to be continuous.
Examples
julia> using StaticRanges
julia> findall(and(>(4), <(10)), 1:10)
5-element Array{Int64,1}:
5
6
7
8
9
julia> find_all(or(<(4), >(6)), 1:10)
7-element GapRange{Int64,UnitRange{Int64},UnitRange{Int64}}:
1
2
3
7
8
9
10