Granularity of interval steps and units

You can customize the granularity with the step and unit builder-style methods on an interval. You use the step method to set the number of items to step or skip by. The unit method specifies the unit, which is necessary for some types of intervals. For example, the granularity of a date interval is expressed in units of time: days, weeks, months, hours. You could iterate across a date interval in 2-week periods, 10-year periods, or 1-month periods.

Each method returns the interval so you can chain the result of one method with the next method. For example:

// Simple int interval visits odd elements
var interv = (1..10).step( 2 )

// Date interval visits two week periods
var span = (date1..date2).step( 2 ).unit( WEEKS )

Notice the WEEKS value, which is an enumeration constant. You do not need to qualify WEEKS with the enumeration type. Gosu can infer the enumeration type so the code is always type-safe.