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 Val is used)
  • Fixed: all parameters are immutable fields of a struct. This is how all ranges in Base are 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.UnitSRangeType
UnitSRange

A 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.

source
StaticRanges.LinSRangeType
LinSRange

A 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.

source
StaticRanges.StepSRangeType
StepSRange

A 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.

source
StaticRanges.StepSRangeLenType
StepSRangeLen

A 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.

source

Mutable Ranges

StaticRanges.UnitMRangeType
UnitMRange

A 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.

source
StaticRanges.LinMRangeType
LinMRange

A 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.

source
StaticRanges.StepMRangeType
StepMRange

A 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.

source
StaticRanges.StepMRangeLenType
StepMRangeLen

A 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.

source

Abstract Ranges

StaticRanges.OneToRangeType
OneToRange

Supertype for OneToSRange and OneToMRange. It's subtypes should behave identically to Base.OneTo.

source

Special Ranges

StaticRanges.GapRangeType
GapRange{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
source