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_firstFunction
can_set_first(x) -> Bool

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

source
StaticRanges.set_first!Function
set_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)
2
source
StaticRanges.set_firstFunction
set_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:10
source
StaticRanges.set_step!Function
set_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)
2
source
StaticRanges.set_stepFunction
set_step(x, st)

Sets the step of x to val.

Examples

julia> using StaticRanges

julia> set_step(1:1:10, 2)
1:2:9
source
StaticRanges.can_set_lastFunction
can_set_last(x) -> Bool

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

source
StaticRanges.set_last!Function
set_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)
5
source
StaticRanges.set_lastFunction
set_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:5
source
StaticRanges.can_set_lengthFunction
can_set_length(x) -> Bool

Returns true if type of x can have its length set independent of changing its first or last position.

source
StaticRanges.set_length!Function
set_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)
20
source
StaticRanges.set_lengthFunction
set_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
source