2008-09-29 21:07:16 +00:00
|
|
|
function $R(start, end, exclusive) {
|
|
|
|
return new ObjectRange(start, end, exclusive);
|
|
|
|
}
|
|
|
|
|
|
|
|
var ObjectRange = Class.create(Enumerable, (function() {
|
|
|
|
function initialize(start, end, exclusive) {
|
2007-01-18 22:24:27 +00:00
|
|
|
this.start = start;
|
|
|
|
this.end = end;
|
|
|
|
this.exclusive = exclusive;
|
2008-09-29 21:07:16 +00:00
|
|
|
}
|
2007-01-18 22:24:27 +00:00
|
|
|
|
2008-09-29 21:07:16 +00:00
|
|
|
function _each(iterator) {
|
2007-01-18 22:24:27 +00:00
|
|
|
var value = this.start;
|
|
|
|
while (this.include(value)) {
|
|
|
|
iterator(value);
|
|
|
|
value = value.succ();
|
|
|
|
}
|
2008-09-29 21:07:16 +00:00
|
|
|
}
|
2007-10-13 11:24:23 +00:00
|
|
|
|
2008-09-29 21:07:16 +00:00
|
|
|
function include(value) {
|
2007-10-13 11:24:23 +00:00
|
|
|
if (value < this.start)
|
|
|
|
return false;
|
|
|
|
if (this.exclusive)
|
|
|
|
return value < this.end;
|
|
|
|
return value <= this.end;
|
|
|
|
}
|
2008-09-29 21:07:16 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
initialize: initialize,
|
|
|
|
_each: _each,
|
|
|
|
include: include
|
|
|
|
};
|
|
|
|
})());
|
2007-01-18 22:24:27 +00:00
|
|
|
|