Project

General

Profile

Actions

Feature #15092

closed

Provide step count in Range constructor

Added by v0dro (Sameer Deshmukh) over 5 years ago. Updated over 5 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:88901]

Description

I would like to propose making changes to the Range constructor so that a user can specify
a step count along with start and stop. Since Ruby 2.6 will introduce a step property
in Ranges anyway I think this will be a useful addition.

Here's my reasons for the changes:

When creating software libraries for numerical computing, it is common to query the data
container for values in a particular range at some given steps. For example, say I have the
following NArray object:

a = NArray.new([1,2,3,4,5,6,7,8,9,10,11,12])

And I want the values 1, 4, 7, 10 and 12, I can simply specify a Range like this:

r = Range.new 0, Float::INFINITY, 3 # start, stop (upto the end), step
a[r]
# => NArray([1, 4, 7, 10, 12])

This can possibly also be extended to Array#[] so that users can get ranges of values at
steps without much worry.


Related issues 1 (0 open1 closed)

Is duplicate of Ruby master - Feature #13904: getter for original information of EnumeratorClosedmrkn (Kenta Murata)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0