Issue #7994 has been reported by alexeymuranov (Alexey Muranov). ---------------------------------------- Feature #7994: Make iterators pass an implicit named parameter `iteration` to the executed block https://bugs.ruby-lang.org/issues/7994 Author: alexeymuranov (Alexey Muranov) Status: Open Priority: Normal Assignee: Category: Target version: =begin I think it would be nice to be able to write something like this: items.each do |item| unless iteration.first? # do something that is not applicable to the first iteration end # do whatever is to be done to all items end =end
[ruby-trunk - Feature #7994][Open] Make iterators pass an implicit named parameter `iteration` to th
on 2013-03-01 16:23
[ruby-trunk - Feature #7994] Make iterators pass an implicit named parameter `iteration` to the exec
on 2013-03-01 16:30
Issue #7994 has been updated by alexeymuranov (Alexey Muranov).
=begin
As a use case, i wanted to create a pagination navigation element on a
web page in ((*Haml*)) template. What i ended up with looks redundant to
me. With the suggested feature, i would be able to do:
%nav.pagination
- [page_ranges_before, page_ranges_after].each do |page_ranges|
- unless iteration.first?
%span.page.active
= active_page
- page_ranges.each do |range|
- unless iteration.first?
%span.ellipsis
⋯
- range.each do |page|
%button.page{ :type => :submit, :name => :page, :value =>
page }
= page
=end
----------------------------------------
Feature #7994: Make iterators pass an implicit named parameter
`iteration` to the executed block
https://bugs.ruby-lang.org/issues/7994#change-37226
Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
=begin
I think it would be nice to be able to write something like this:
items.each do |item|
unless iteration.first?
# do something that is not applicable to the first iteration
end
# do whatever is to be done to all items
end
=end
Re: [ruby-trunk - Feature #7994][Open] Make iterators pass an implicit named parameter `iteration` t
on 2013-03-01 16:32
On 01/03/13 15:21, alexeymuranov (Alexey Muranov) wrote: > > Issue #7994 has been reported by alexeymuranov (Alexey Muranov). What advantages does this have over: items.drop(1).each do |item| or items[1..-1].each do |item| or to invert it: items.first.tap do |item| ? -- Alex
[ruby-trunk - Feature #7994] Make iterators pass an implicit named parameter `iteration` to the exec
on 2013-03-01 17:03
Issue #7994 has been updated by alexeymuranov (Alexey Muranov). regularfry (Alex Young) wrote: > items[1..-1].each do |item| > > or to invert it: > > items.first.tap do |item| > > ? Sorry, i didn't understand, how do you plan to use this? ---------------------------------------- Feature #7994: Make iterators pass an implicit named parameter `iteration` to the executed block https://bugs.ruby-lang.org/issues/7994#change-37229 Author: alexeymuranov (Alexey Muranov) Status: Open Priority: Normal Assignee: Category: Target version: =begin I think it would be nice to be able to write something like this: items.each do |item| unless iteration.first? # do something that is not applicable to the first iteration end # do whatever is to be done to all items end =end
[ruby-trunk - Feature #7994][Rejected] Make iterators pass an implicit named parameter `iteration` t
on 2013-03-01 19:52
Issue #7994 has been updated by matz (Yukihiro Matsumoto). Status changed from Open to Rejected Nice idea. But I reject the idea for Ruby for two reasons: * I personally don't like implicit parameters * That might cause incompatibility by conflicting with existing local variable name Maybe good for a new language without existing set of programs. Matz. ---------------------------------------- Feature #7994: Make iterators pass an implicit named parameter `iteration` to the executed block https://bugs.ruby-lang.org/issues/7994#change-37235 Author: alexeymuranov (Alexey Muranov) Status: Rejected Priority: Normal Assignee: Category: Target version: =begin I think it would be nice to be able to write something like this: items.each do |item| unless iteration.first? # do something that is not applicable to the first iteration end # do whatever is to be done to all items end =end
[ruby-trunk - Feature #7994] Make iterators pass an implicit named parameter `iteration` to the exec
on 2013-03-01 20:28
Issue #7994 has been updated by alexeymuranov (Alexey Muranov).
=begin
Ok, then i make a last try: what about adding it in the end of parameter
list as an optional parameter?
items.each do |item, iteration|
unless iteration.first?
# do something that is not applicable to the first iteration
end
# do whatever is to be done to all items
end
=end
----------------------------------------
Feature #7994: Make iterators pass an implicit named parameter
`iteration` to the executed block
https://bugs.ruby-lang.org/issues/7994#change-37236
Author: alexeymuranov (Alexey Muranov)
Status: Rejected
Priority: Normal
Assignee:
Category:
Target version:
=begin
I think it would be nice to be able to write something like this:
items.each do |item|
unless iteration.first?
# do something that is not applicable to the first iteration
end
# do whatever is to be done to all items
end
=end
[ruby-trunk - Feature #7994] Make iterators pass an implicit named parameter `iteration` to the exec
on 2013-03-01 20:35
Issue #7994 has been updated by marcandre (Marc-Andre Lafortune). Please think about the number of incompatibilities this would bring... not all enumerables are sequences of single items. Just use `each_with_index` and `index.zero?` instead of `iteration.first?` ---------------------------------------- Feature #7994: Make iterators pass an implicit named parameter `iteration` to the executed block https://bugs.ruby-lang.org/issues/7994#change-37237 Author: alexeymuranov (Alexey Muranov) Status: Rejected Priority: Normal Assignee: Category: Target version: =begin I think it would be nice to be able to write something like this: items.each do |item| unless iteration.first? # do something that is not applicable to the first iteration end # do whatever is to be done to all items end =end
[ruby-trunk - Feature #7994] Make iterators pass an implicit named parameter `iteration` to the exec
on 2013-03-01 20:46
Issue #7994 has been updated by alexeymuranov (Alexey Muranov). Marc-Andre, thanks for the idea, i did not realize that `each_with_index` works with all enumerables. However i was hoping that something like `unless iteration.first?` could be some day optimized away by a compiler to not check on every iteration. I also do not see right away an incompatibility introduced by my second proposal (about the original one you are right). ---------------------------------------- Feature #7994: Make iterators pass an implicit named parameter `iteration` to the executed block https://bugs.ruby-lang.org/issues/7994#change-37238 Author: alexeymuranov (Alexey Muranov) Status: Rejected Priority: Normal Assignee: Category: Target version: =begin I think it would be nice to be able to write something like this: items.each do |item| unless iteration.first? # do something that is not applicable to the first iteration end # do whatever is to be done to all items end =end
[ruby-trunk - Feature #7994] Make iterators pass an implicit named parameter `iteration` to the exec
on 2013-03-01 21:11
Issue #7994 has been updated by marcandre (Marc-Andre Lafortune). > I also do not see right away an incompatibility introduced by my second proposal (about the original one you are right). #before [[1,2]].each{|a, b| p a, b} # => 1, then 2 # after [[1,2]].each{|a, b| p a, b} # => [1, 2], then<#your iteration object> BTW, all hashes would be affected like this! ---------------------------------------- Feature #7994: Make iterators pass an implicit named parameter `iteration` to the executed block https://bugs.ruby-lang.org/issues/7994#change-37240 Author: alexeymuranov (Alexey Muranov) Status: Rejected Priority: Normal Assignee: Category: Target version: =begin I think it would be nice to be able to write something like this: items.each do |item| unless iteration.first? # do something that is not applicable to the first iteration end # do whatever is to be done to all items end =end
[ruby-trunk - Feature #7994] Make iterators pass an implicit named parameter `iteration` to the exec
on 2013-03-01 21:31
Issue #7994 has been updated by alexeymuranov (Alexey Muranov). Ok, i see. ---------------------------------------- Feature #7994: Make iterators pass an implicit named parameter `iteration` to the executed block https://bugs.ruby-lang.org/issues/7994#change-37241 Author: alexeymuranov (Alexey Muranov) Status: Rejected Priority: Normal Assignee: Category: Target version: =begin I think it would be nice to be able to write something like this: items.each do |item| unless iteration.first? # do something that is not applicable to the first iteration end # do whatever is to be done to all items end =end
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.