Project

General

Profile

Actions

Feature #16812

closed

Allow slicing arrays with ArithmeticSequence

Added by zverok (Victor Shepelev) over 4 years ago. Updated about 4 years ago.

Status:
Closed
Target version:
-
[ruby-core:98034]

Description

I believe when concepts of ArithmeticSequence and Range#% were introduced, one of the main intended usages was array slicing in scientific data processing. So, it seems to make sense to allow this in Array#[]:

ary[(5..20) % 2] # each second element between 5 and 20
ary[(0..) % 3] # each third element
ary[10.step(by: -1)] # elements 10, 9, 8, 7 ....

PR is here.

My reasoning is as follows:

  1. As stated above, ArithmeticSequence and Range#% seem to have been introduced exactly for this goal
  2. Python has its slicing syntax as begin:end:step (with a possibility to omit either), and it seems to be well respected and used feature for data processing. So I believe it is useful, and relatively easy to integrate into existing functionality

I expect the usual "it is ugly and unreadable!" backlash.
I don't have an incentive, nor energy, to "defend" the proposal, so I would not.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0