Ranges

Generic ranges for any value that is Ordered. Range objects are Enumerable.

Range → Object

An object containing a range's beginning, end, and exclusivity.

a .. b → Range

Create an inclusive Range from a to b.

a ... b → Range

Create an exclusive Range from a to b.

r start → any
  | r is-a?: Range

The start of the range.

Example:

> ($a .. $z) start
$a
r end → any
  | r is-a?: Range

The end of the range.

Example:

> ($a .. $z) end
$z
r exclusive? → Boolean
  | r is-a?: Range

Is a range exclusive?

Example:

> ($a .. $z) exclusive?
False
> ($a ... $z) exclusive?
True
r matches?: x → Boolean
  | r is-a?: Range

Test if x is within the bounds of the range. This is useful for case-of:.

Example:

> ($a .. $z) matches?: $z
True
> ($a ... $z) matches?: $z
False
> $z case-of: { $a .. $w -> @foo; $x .. $z -> @bar }
@bar
r step &size: 1 → List
  | r is-a?: Range

Returns a list of the values in the range, increasing by size.

Example:

> ($a .. $f) step
[$a, $b, $c, $d, $e, $f]
> ($a .. $f) step &size: 2
[$a, $c, $e]
r step: action &size: 1 → List
  | r is-a?: Range

Returns a list of the values in the range, increasing by size, sent to action.

Example:

> ($a .. $f) step: @show
["$a", "$b", "$c", "$d", "$e", "$f"]
> ($a .. $f) step: @show &size: 2
["$a", "$c", "$e"]
r collect: action → List
  | r is-a?: Range

Alias for step:.