Files
wren/doc/site/modules/core/range.markdown
T

58 lines
1.3 KiB
Markdown
Raw Normal View History

2015-01-18 15:36:36 -08:00
^title Range Class
2015-09-22 21:19:38 -07:00
A range defines a bounded range of values from a starting point to a possibly
exclusive endpoint. [Here](../range.html) is a friendly introduction.
2015-01-18 15:36:36 -08:00
Extends [Sequence](sequence.html).
2015-03-27 07:43:36 -07:00
## Methods
2015-01-18 15:36:36 -08:00
### **from**
2015-09-22 21:19:38 -07:00
The starting point of the range. A range may be backwards, so this can be
greater than [to].
:::wren
System.print((3..5).min) //> 3
System.print((4..2).min) //> 4
2015-01-18 15:36:36 -08:00
### **to**
2015-09-22 21:19:38 -07:00
The endpoint of the range. If the range is inclusive, this value is included,
otherwise it is not.
:::wren
System.print((3..5).min) //> 5
System.print((4..2).min) //> 2
2015-01-18 15:36:36 -08:00
### **min**
2015-09-22 21:19:38 -07:00
The minimum bound of the range. Returns either `from`, or `to`, whichever is
lower.
:::wren
System.print((3..5).min) //> 3
System.print((4..2).min) //> 2
2015-01-18 15:36:36 -08:00
### **max**
2015-09-22 21:19:38 -07:00
The maximum bound of the range. Returns either `from`, or `to`, whichever is
greater.
:::wren
System.print((3..5).min) //> 5
System.print((4..2).min) //> 4
2015-01-18 15:36:36 -08:00
### **isInclusive**
2015-09-22 21:19:38 -07:00
Whether or not the range includes `to`. (`from` is always included.)
:::wren
System.print((3..5).isInclusive) //> true
System.print((3...5).isInclusive) //> false
2015-01-18 15:36:36 -08:00
### **iterate**(iterator), **iteratorValue**(iterator)
2015-09-22 21:19:38 -07:00
Iterates over the range. Starts at `from` and increments by one towards `to`
until the endpoint is reached.