Issue #14114 has been reported by eike.rb (Eike Dierks).

----------------------------------------
Bug #14114: Add #step for Array, Enumerable, Enumerator
https://bugs.ruby-lang.org/issues/14114

* Author: eike.rb (Eike Dierks)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
This must have been discussed before,
please reassigned and close this one.

I want to propose an extension to the ruby core api:
- add #step(n) for Enumerable, Enumerator
- coerce the step() api across all the api (see Numeric#step(by:n, to:m))
- extend to: #step((by:n, to:m, offset:k)

We have Range#step,
but #step is not yet defined for Array, Enumerable, Enumerator

I believe, the semantics of #step, as defined in Range
applies like well for Enumerable and Enumerator

It should return every n'th element of the collection.

As of 2.4 #step is not yet defined for Enumerable/Enumerator.
But the semantics of this method is already well defined for Range.

That same semantics should also apply for Enumerable#step(n)
aka: pick every n'th element.

Examples:

('a'..'z').step(2)
=> #<Enumerator: ...>

('a'..'z').to_a.step(2)
NoMethodError: undefined method `step'

('a'..'z').to_enum.step(2)
NoMethodError: undefined method `step'





























-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>