On Jun 19, 4:57 am, Robert D. [email protected] wrote:
coll.map.each_slice(n){ … }
I would simply stick with the existing behavior.
I will not let the absence of use cases let ruin my work Now I have
always liked Tom’s reach for perfection, but on a practical base I
agree with Robert it is probably not worth it.
Robert… someone understands me!
for Enumerators only
Thus [1,2,3].map{|a,b| [a,b]} would still be [[1, nil]…]
but
[1,2,3].to_enum.map{|a,b| [a,b]} would be [[1,2],[3,nil]]
Though I think that would be kind of confusing, if not problematic.
As others have pointed out there is no way to query the parenthetical
patterns, eg. |(a,b)| so this will be somewhat more limited but I was
thinking of something like:
[1,2,3].each.by_arity{ |a,b| … }
or conversely
[1,2,3].by_arity.each{ |a,b| … }
But we’d still need a way to do #each_cons by arity. To do this I
think there would need to be an equivalence. #each_slice is to #each
as #each_cons is to ___ ? So we define a method #cons that normally
means each_cons(1). Then…
[1,2,3].cons.by_arity{ |a,b| … }
or conversely
[1,2,3].by_arity.cons{ |a,b| … }
Though honestly this makes me wonder why #each just doesn take an
optional slice number – why have a completely separate method for
the special case of n=1, when an optional argument would do? Indeed
Facets has #each_by that does this.
P.S. I am half tempted to alias #each_by as #air, as in “air your
arguments”, and then name the cons version #conair
T.