Range
type Range
Range — a range computes everything from its two bounds; items materializes the elements into a real list when one is needed.
Implements Enumerable, Foldable.
Methods
reduce Enumerable Foldable
reduce(acc, f)
Shared primitive for Enumerable and Foldable. Range stays structurally minimal; inherited operations reduce over its materialized items in ascending range order.
sum
Numeric range aggregates are expressed in terms of the Enumerable primitive rather than relying on the walker's historical List fallback.
contains?
contains?(value)
Membership is a Range method, not a fallback into the bare String/List native dispatcher.
items
The range's elements as a list.
Examples
(1..3).items # => [1, 2, 3]
('a'..'c').items # => ['a', 'b', 'c']
first
The list operations, over the materialized items. A range is an ordered collection, so (1..5).first and (1..5).length are questions it can answer — and on the BEAM backend, where a range IS its item list, they already worked. Only the walker rejected them ("Undefined method: first for Range"), so every one of these was a backend divergence rather than a deliberate restriction.
sort
sort(comparator)
join
join(separator)
at
at(index, fallback)
take
take(n)
drop
drop(n)
indexOf
indexOf(value)
zip
zip(other)
partition
partition(pred)
push
push(value)
reject
reject(pred)
From Enumerable
map- Transforms each item by applying
f, collecting the results into a list. mapIndexed- Transforms each item together with its 0-based position, collecting the results into a list.
filter- Keeps the items for which
predholds. flatMap- Maps each item to a list and concatenates the results.
collect- Maps each item through
f(returning anOptional), keeping and unwrapping theJust(y)results and droppingNone.
From Foldable
each- Applies
fto each item for its side effects. eachIndexed- Applies
fto each item together with its 0-based position, for side effects. all?- True if every item satisfies
pred. any?- True if at least one item satisfies
pred. find- The first item satisfying
predwrapped in Just, or None.