ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:61233] [ruby-trunk - Feature #9587] [Open] Integer#times with optional starting value
       [not found] <redmine.issue-9587.20140302195238@ruby-lang.org>
@ 2014-03-02 19:52 ` sawadatsuyoshi
  2014-03-02 21:17 ` [ruby-core:61234] [ruby-trunk - Feature #9587] " ruby-core
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: sawadatsuyoshi @ 2014-03-02 19:52 UTC (permalink / raw)
  To: ruby-core

Issue #9587 has been reported by Tsuyoshi Sawada.

----------------------------------------
Feature #9587: Integer#times with optional starting value
https://bugs.ruby-lang.org/issues/9587

* Author: Tsuyoshi Sawada
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
Just like `Enumerator#with_index` takes an optional argument that specifies the initial value of the index, I would like to request that `Integer#times` take an optional argument that specifies the initial value. The usefulness of it is similar to that of `with_index` taking an argument. We sometimes want to repeat tasks a given number of times, and want to use an index not necessarily starting from `0`.

    6.times(1){|i| puts "Chapter #{i}"}

should give

    Chapter 1
    Chapter 2
    Chapter 3
    Chapter 4
    Chapter 5
    Chapter 6

with the return value `6`. We can do it with `1.upto(6)`, or with `#{i + 1}` within the block, but giving the initial value to `times` is much easier.



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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ruby-core:61234] [ruby-trunk - Feature #9587] Integer#times with optional starting value
       [not found] <redmine.issue-9587.20140302195238@ruby-lang.org>
  2014-03-02 19:52 ` [ruby-core:61233] [ruby-trunk - Feature #9587] [Open] Integer#times with optional starting value sawadatsuyoshi
@ 2014-03-02 21:17 ` ruby-core
  2014-03-03 11:17 ` [ruby-core:61254] " sawadatsuyoshi
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: ruby-core @ 2014-03-02 21:17 UTC (permalink / raw)
  To: ruby-core

Issue #9587 has been updated by Marc-Andre Lafortune.


How exactly would it be easier than `1.upto(6)`?

----------------------------------------
Feature #9587: Integer#times with optional starting value
https://bugs.ruby-lang.org/issues/9587#change-45580

* Author: Tsuyoshi Sawada
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
Just like `Enumerator#with_index` takes an optional argument that specifies the initial value of the index, I would like to request that `Integer#times` take an optional argument that specifies the initial value. The usefulness of it is similar to that of `with_index` taking an argument. We sometimes want to repeat tasks a given number of times, and want to use an index not necessarily starting from `0`.

    6.times(1){|i| puts "Chapter #{i}"}

should give

    Chapter 1
    Chapter 2
    Chapter 3
    Chapter 4
    Chapter 5
    Chapter 6

with the return value `6`. We can do it with `1.upto(6)`, or with `#{i + 1}` within the block, but giving the initial value to `times` is much easier.



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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ruby-core:61254] [ruby-trunk - Feature #9587] Integer#times with optional starting value
       [not found] <redmine.issue-9587.20140302195238@ruby-lang.org>
  2014-03-02 19:52 ` [ruby-core:61233] [ruby-trunk - Feature #9587] [Open] Integer#times with optional starting value sawadatsuyoshi
  2014-03-02 21:17 ` [ruby-core:61234] [ruby-trunk - Feature #9587] " ruby-core
@ 2014-03-03 11:17 ` sawadatsuyoshi
  2014-03-03 12:24 ` [ruby-core:61256] " eregontp
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: sawadatsuyoshi @ 2014-03-03 11:17 UTC (permalink / raw)
  To: ruby-core

Issue #9587 has been updated by Tsuyoshi Sawada.


Marc-Andre Lafortune wrote:
> How exactly would it be easier than `1.upto(6)`?

When the start value is `1`, the argument `6` of `upto` coincidentally matches what would be the receiver of `times`, and you may not see the benifit, but when it is some other value such as `5`, then you would need to calculate that in mind:

    5.upto(11) # Need to calculate 11 (= 5 + 6)
    6.times(5) # This is easier

A use case maybe when you are writing labels for pagination buttons. You know the start value, say 17, and you want to display ten next pages. Then,

    10.times(17){|i| ...}

would give i = 17, 18, ..., 26. Doing this with `upto` or addition to the index within a `times` block may be a cause of careless bugs.

----------------------------------------
Feature #9587: Integer#times with optional starting value
https://bugs.ruby-lang.org/issues/9587#change-45594

* Author: Tsuyoshi Sawada
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
Just like `Enumerator#with_index` takes an optional argument that specifies the initial value of the index, I would like to request that `Integer#times` take an optional argument that specifies the initial value. The usefulness of it is similar to that of `with_index` taking an argument. We sometimes want to repeat tasks a given number of times, and want to use an index not necessarily starting from `0`.

    6.times(1){|i| puts "Chapter #{i}"}

should give

    Chapter 1
    Chapter 2
    Chapter 3
    Chapter 4
    Chapter 5
    Chapter 6

with the return value `6`. We can do it with `1.upto(6)`, or with `#{i + 1}` within the block, but giving the initial value to `times` is much easier.



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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ruby-core:61256] [ruby-trunk - Feature #9587] Integer#times with optional starting value
       [not found] <redmine.issue-9587.20140302195238@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2014-03-03 11:17 ` [ruby-core:61254] " sawadatsuyoshi
@ 2014-03-03 12:24 ` eregontp
  2014-03-03 20:09   ` [ruby-core:61262] " Matthew Kerwin
  2014-03-03 20:10 ` [ruby-core:61263] " matthew
  2020-01-04 17:28 ` [ruby-core:96654] [Ruby master Feature#9587] " sawadatsuyoshi
  5 siblings, 1 reply; 7+ messages in thread
From: eregontp @ 2014-03-03 12:24 UTC (permalink / raw)
  To: ruby-core

Issue #9587 has been updated by Benoit Daloze.


"10.times(17)" is 170 at me, so it definitely is not an option as an unnamed argument.

----------------------------------------
Feature #9587: Integer#times with optional starting value
https://bugs.ruby-lang.org/issues/9587#change-45596

* Author: Tsuyoshi Sawada
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
Just like `Enumerator#with_index` takes an optional argument that specifies the initial value of the index, I would like to request that `Integer#times` take an optional argument that specifies the initial value. The usefulness of it is similar to that of `with_index` taking an argument. We sometimes want to repeat tasks a given number of times, and want to use an index not necessarily starting from `0`.

    6.times(1){|i| puts "Chapter #{i}"}

should give

    Chapter 1
    Chapter 2
    Chapter 3
    Chapter 4
    Chapter 5
    Chapter 6

with the return value `6`. We can do it with `1.upto(6)`, or with `#{i + 1}` within the block, but giving the initial value to `times` is much easier.



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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ruby-core:61262] Re: [ruby-trunk - Feature #9587] Integer#times with optional starting value
  2014-03-03 12:24 ` [ruby-core:61256] " eregontp
@ 2014-03-03 20:09   ` Matthew Kerwin
  0 siblings, 0 replies; 7+ messages in thread
From: Matthew Kerwin @ 2014-03-03 20:09 UTC (permalink / raw)
  To: Ruby developers

[-- Attachment #1: Type: text/plain, Size: 195 bytes --]

On Mar 3, 2014 10:25 PM, <eregontp@gmail.com> wrote:
>
> "10.times(17)" is 170 at me, so it definitely is not an option as an
unnamed argument.

Strongly agree. Maybe suggest: 10.times(from: 17)

[-- Attachment #2: Type: text/html, Size: 278 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ruby-core:61263] [ruby-trunk - Feature #9587] Integer#times with optional starting value
       [not found] <redmine.issue-9587.20140302195238@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2014-03-03 12:24 ` [ruby-core:61256] " eregontp
@ 2014-03-03 20:10 ` matthew
  2020-01-04 17:28 ` [ruby-core:96654] [Ruby master Feature#9587] " sawadatsuyoshi
  5 siblings, 0 replies; 7+ messages in thread
From: matthew @ 2014-03-03 20:10 UTC (permalink / raw)
  To: ruby-core

Issue #9587 has been updated by Matthew Kerwin.


 On Mar 3, 2014 10:25 PM, <eregontp@gmail.com> wrote:
 >
 > "10.times(17)" is 170 at me, so it definitely is not an option as an
 unnamed argument.
 
 Strongly agree. Maybe suggest: 10.times(from: 17)

----------------------------------------
Feature #9587: Integer#times with optional starting value
https://bugs.ruby-lang.org/issues/9587#change-45602

* Author: Tsuyoshi Sawada
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
Just like `Enumerator#with_index` takes an optional argument that specifies the initial value of the index, I would like to request that `Integer#times` take an optional argument that specifies the initial value. The usefulness of it is similar to that of `with_index` taking an argument. We sometimes want to repeat tasks a given number of times, and want to use an index not necessarily starting from `0`.

    6.times(1){|i| puts "Chapter #{i}"}

should give

    Chapter 1
    Chapter 2
    Chapter 3
    Chapter 4
    Chapter 5
    Chapter 6

with the return value `6`. We can do it with `1.upto(6)`, or with `#{i + 1}` within the block, but giving the initial value to `times` is much easier.



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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ruby-core:96654] [Ruby master Feature#9587] Integer#times with optional starting value
       [not found] <redmine.issue-9587.20140302195238@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2014-03-03 20:10 ` [ruby-core:61263] " matthew
@ 2020-01-04 17:28 ` sawadatsuyoshi
  5 siblings, 0 replies; 7+ messages in thread
From: sawadatsuyoshi @ 2020-01-04 17:28 UTC (permalink / raw)
  To: ruby-core

Issue #9587 has been updated by sawa (Tsuyoshi Sawada).


I now think that writing as below is good enough:

```ruby
6.times.with_index(1){|_, i| puts "Chapter#{i}"}

```

I withdraw this proposal. Please close it.

----------------------------------------
Feature #9587: Integer#times with optional starting value
https://bugs.ruby-lang.org/issues/9587#change-83624

* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Just like `Enumerator#with_index` takes an optional argument that specifies the initial value of the index, I would like to request that `Integer#times` take an optional argument that specifies the initial value. The usefulness of it is similar to that of `with_index` taking an argument. We sometimes want to repeat tasks a given number of times, and want to use an index not necessarily starting from `0`.

    6.times(1){|i| puts "Chapter #{i}"}

should give

    Chapter 1
    Chapter 2
    Chapter 3
    Chapter 4
    Chapter 5
    Chapter 6

with the return value `6`. We can do it with `1.upto(6)`, or with `#{i + 1}` within the block, but giving the initial value to `times` is much easier.



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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-01-04 17:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-9587.20140302195238@ruby-lang.org>
2014-03-02 19:52 ` [ruby-core:61233] [ruby-trunk - Feature #9587] [Open] Integer#times with optional starting value sawadatsuyoshi
2014-03-02 21:17 ` [ruby-core:61234] [ruby-trunk - Feature #9587] " ruby-core
2014-03-03 11:17 ` [ruby-core:61254] " sawadatsuyoshi
2014-03-03 12:24 ` [ruby-core:61256] " eregontp
2014-03-03 20:09   ` [ruby-core:61262] " Matthew Kerwin
2014-03-03 20:10 ` [ruby-core:61263] " matthew
2020-01-04 17:28 ` [ruby-core:96654] [Ruby master Feature#9587] " sawadatsuyoshi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).