Manipulating Ranges
There are options for in place mutations and corresponding non mutating operations. These allow safe mutation of ranges by avoiding states that are typically prohibited at time of construction. For example, OneToMRange cannot have a negative value for it's stop field. These methods are also called whenever setproperty! is used.
StaticRanges.can_set_first — Functioncan_set_first(x) -> BoolReturns true if the first element of x can be set. If x is a range then changing the first element will also change the length of x.
StaticRanges.set_first! — Functionset_first!(x, val)Set the first element of x to val.
Examples
julia> using StaticRanges
julia> mr = UnitMRange(1, 10);
julia> set_first!(mr, 2);
julia> first(mr)
2StaticRanges.set_first — Functionset_first(x, val)Returns similar type as x with first value set to val.
Examples
julia> using StaticRanges
julia> r = set_first(1:10, 2)
2:10StaticRanges.can_set_step — Functioncan_set_step(x) -> BoolReturns true if type of x has step field that can be set.
StaticRanges.set_step! — Functionset_step!(x, st)Sets the step of x to val.
Examples
julia> using StaticRanges
julia> mr = StepMRange(1, 1, 10);
julia> set_step!(mr, 2);
julia> step(mr)
2StaticRanges.set_step — Functionset_step(x, st)Sets the step of x to val.
Examples
julia> using StaticRanges
julia> set_step(1:1:10, 2)
1:2:9StaticRanges.can_set_last — Functioncan_set_last(x) -> BoolReturns true if the last element of x can be set. If x is a range then changing the first element will also change the length of x.
StaticRanges.set_last! — Functionset_last!(x, val)Set the last element of x to val.
Examples
julia> using StaticRanges
julia> mr = UnitMRange(1, 10);
julia> set_last!(r, 5);
julia> last(mr)
5StaticRanges.set_last — Functionset_last(x, val)Returns a similar type as x with its last value equal to val.
Examplse
julia> using StaticRanges
julia> set_last(1:10, 5)
1:5StaticRanges.can_set_length — Functioncan_set_length(x) -> BoolReturns true if type of x can have its length set independent of changing its first or last position.
StaticRanges.set_length! — Functionset_length!(x, len)Returns a similar type as x with a length equal to len.
Examples
julia> using StaticRanges
julia> mr = UnitMRange(1, 10);
julia> set_length!(mr, 20);
julia> length(mr)
20StaticRanges.set_length — Functionset_length(x, len)Change the length of x while maintaining it's first and last positions.
Examples
julia> using StaticRanges
julia> set_length(1:10, 20)
1:20