Category talk:Wren-trait: Difference between revisions

Content added Content deleted
(→‎Source code: Comparable now inherits from Cloneable.)
(→‎Source code: Added two more constructors to Stepped class.)
Line 43: Line 43:
_seq = seq
_seq = seq
_step = (step < 1) ? 1 : step // minimum step of 1
_step = (step < 1) ? 1 : step // minimum step of 1
}

// Ensures a range is ascending before passing it to the constructor.
// It it isn't, returns an empty range. Useful when bounds are variable.
static ascend(range, step) {
if (!(range is Range)) Fiber.abort("First argument must be a range.")
return (range.from <= range.to) ? new(range, step) : 0...0
}

// Ensures a range is descending before passing it to the constructor.
// It it isn't, returns an empty range. Useful when bounds are variable.
static descend(range, step) {
if (!(range is Range)) Fiber.abort("First argument must be a range.")
return (range.from >= range.to) ? new(range, step) : 0...0
}
}