Io Reference







Core   /   Range   /   Range





Simple datastructure representing the items at and between two specific points.
 
 
 



asList

Returns a list containing all the items within and including the ranges starting and ending points.
at(position)

Rewinds the range, skips forward until we're at the supplied position then returns the value at that position. Raises an exception if the position is out of bounds.
contains

Returns a boolean value if the range contains the argument.
first

Moves the current cursor to the beginning of the range, and returns it.
foreach(optionalIndex, value, message)

Iterates over each item beginning with the starting point, and finishing at the ending point inclusive. This method can operate several ways; these include: (1) Takes one argument, the message tree to be executed during each iteration; (2) Takes two arguments, the first argument is the name of the current value being iterated over, and the second is the message tree to be executed during each iteration; (3) Takes three arguments: the first is the current index within the range, the second is the name of the current value being iterated over, and the third is the message tree to be executed during each iteration. For example:
// First method (operating on numbers)
1 to(10) foreach("iterating" print) // prints "iterating" 10 times
// Second method (operating on numbers)
1 to(10) foreach(v, v print) // prints each value
// Third method (operating on numbers)
1 to(10) foreach(i, v, writeln(i .. ": " .. v)) // prints "index: value"
index

Returns the current index number starting from zero and extending outward up to the maximum number of items in the range.
indexOf(aValue)

Calculates each value, checking to see if it matches the aValue parameter. If so, return the position within the range. NOTE: This method rewinds the range before searching. If you need to revert back to your original position, make a duplicate of the range, and use indexOf on it instead.
last

Moves the current cursor to the end of the range, and returns it.
levenshtein(other)

Returns the levenshtein distance to other.
map(optionalIndex, value, message)

Returns a new list which contains the result of the 'body' for every element stepped over in the range, from the starting point to the ending point inclusive. This method can operate several ways; these include: (1) Takes one argument, the message tree to be executed during each iteration; (2) Takes two arguments, the first argument is the name of the current value being iterated over, and the second is the message tree to be executed during each iteration; (3) Takes three arguments: the first is the current index within the range, the second is the name of the current value being iterated over, and the third is the message tree to be executed during each iteration. For example:
# First method (operating on numbers)
1 to(10) map(*2) # multiply each value by two
# Second method (operating on numbers)
1 to(10) map(v, "#{v}" interpolate) # returns string representation of each value as list
# Third method (operating on numbers)
1 to(10) map(i, v, i*v) #  multiply each value by index
next

Sets the current item in the range to the next item in the range, and returns a boolean value indicating whether it is not at the end of the range.
nextInSequence(skipVal)

Returns the next item in the sequence. The optional skipVal parameter allows you to skip ahead skipVal places.
previous

Sets the current item in the range to the previous item in the range, and returns a boolean value indicating whether it is not at the beginning of the range.
rewind

Sets the current item and the index to the values the receiver started out with.
select

Operates the same as 'List select'
setRange(start, end, increment)

Has several modes of operation. First, if only two parameters are specified, the increment value is set to 1 by default, while the first parameter represents the point to start from, and the second parameter represents the point to end at. If the second parameter is smaller than the first, the range will operate backwards. If the third parameter is specified, a custom iteration value will be used instead of 1.
slice(start, end, [by])

Returns a list containing the values from the Range starting at the start parameter, ending at the end parameter, and optionally incremented by the by parameter.
to

Convenience constructor that returns a cursor object representing the range of numbers from the receiver to the 'endingPoint' parameter. Increments over each item in that range by 1.
to(endpoint)

Convenience constructor that returns a range of sequences from the receiver to the endpoint argument. Increments over each item in that range by 1.
toBy(endingPoint, incrementValue)

Convenience constructor that returns a cursor object representing the range of numbers from the receiver to the 'endingPoint' parameter. Increments over each item in that range by the 'incrementValue' parameter.
toBy(endpoint, increment)

Convenience constructor that returns a range of sequences from the receiver to the endpoint argument. Increments over each item in that range by the value of the increment parameter. The increment parameter must be positive.
value

Returns the value of the current item in the range.