A finite arithmetic sequence of integers.
A sequence has a start, end, and step. It is either ascending (step > 0) or descending (step < 0). The default step is 1.
start
end
step
The members of a sequence are defined as:
To construct a sequence, use method IntSeq():
IntSeq()
ascending = IntSeq(2, 5) empty = IntSeq(5, 2)
To set a step other than 1, use method step():
step()
descending = IntSeq(5, 2).step(-2)
To iterate over a sequence, use method map():
map()
numbers = IntSeq(2, 5).map((n) -> n * 2)
A sequence can also be iterated over in a for-generator:
numbers { for (n in IntSeq(2, 5)) { n * 2 } }
Two sequences are equal if and only if they contain the same members in the same order.
Facts:
IntSeq(2, 5) == IntSeq(2, 5) IntSeq(2, -3) == IntSeq(2, -2) // both empty IntSeq(2, 5).step(2) == IntSeq(2, 4).step(2)
The start of this sequence.
IntSeq(2, 5).start == 2
The inclusive end of this sequence.
Note that end may or may not be a member of this sequence.
IntSeq(2, 5).start == 5
The common difference of successive members of this sequence.
IntSeq(5, 2).step == 1 IntSeq(5, 2).step(-2).step == -2
Returns the class of this.
this
Returns a string representation of this.
This method is used to convert the values of string interpolation expressions to strings.
Returns this |> transform if this is non-null, and null otherwise.
this |> transform
null
This method is the complement of the ?? operator and the equivalent of an Option type's map and flatMap methods.
??
Option
map
flatMap
Changes step to newValue.
newValue
Folds this sequence in iteration order using operator, starting with initial.
operator
initial
Applies mapper to each member of this sequence and returns the resulting values as a list.
mapper
IntSeq(2, 5).map((it) -> it) == List(2, 3, 4, 5) IntSeq(5, 2).map((it) -> it) == List() IntSeq(5, 2).step(-1).map((it) -> it * 2) == List(10, 8, 6, 4)
Converts the elements of this sequence to a List.
List
Converts the elements of this sequence to a Listing.
Listing
A finite arithmetic sequence of integers.