Project

General

Profile

Actions

Feature #7006

closed

Add Enumerable#grouped_in as a each_slice without the block

Added by rosenfeld (Rodrigo Rosenfeld Rosas) over 12 years ago. Updated over 12 years ago.

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

Description

I'd like to transform [1, 2, 3, 4] into [[1, 2], [3, 4]].

Currently I can use something like:

a = []; [1, 2, 3, 4].each_slice(2){|chunk| a << chunk}

But I'd prefer to write just:

a = [1, 2, 3, 4].grouped_in(2)

Or any other method name you would choose, like "slices" or something else.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0