[ruby-trunk - Feature #7877][Assigned] E::Lazy#with_index needed

Issue #7877 has been reported by shyouhei (Shyouhei U.).


Feature #7877: E::Lazy#with_index needed

Author: shyouhei (Shyouhei U.)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: next minor

なんかLazyの有効な例を出そうと思ってそうだライプニッツ級数だ!ということで

def leibniz(n)
(0…Float::INFINITY).lazy.with_index {|i, j| (-1 ** j) / (2*i+1).to_f
}.take(n).reduce(:+)
end

とかやっても動かない(いや動くけど。止まらん)。残念です。これあったほうが便利じゃないですかね。どうでしょう。

あ、もちろん2.0.0以降でOKです。

Issue #7877 has been updated by nobu (Nobuyoshi N.).

File 0001-enumerator.c-Enumerator-Lazy-with_index.patch added
Description updated


Feature #7877: E::Lazy#with_index needed

Author: shyouhei (Shyouhei U.)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: next minor

=begin
なんかLazyの有効な例を出そうと思ってそうだライプニッツ級数だ!ということで

def leibniz(n)
(0…Float::INFINITY).lazy.with_index {|i, j| (-1 ** j) /
(2*i+1).to_f }.take(n).reduce(:+)
end

とかやっても動かない(いや動くけど。止まらん)。残念です。これあったほうが便利じゃないですかね。どうでしょう。

あ、もちろん2.0.0以降でOKです。
=end

Issue #7877 has been updated by shyouhei (Shyouhei U.).

Description updated

OK, so @marcandre is interested in. I re-wrote the description in
English.

Feature #7877: E::Lazy#with_index needed

Author: shyouhei (Shyouhei U.)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: next minor

=begin
So I wanted some real benefit of being lazy. I wrote a Leibniz formula:

def leibniz(n)
(0…Float::INFINITY).lazy.with_index {|i, j| (-1 ** j) /
(2*i+1).to_f }.take(n).reduce(:+)
end

But it doesn’t work (well, it does, indeed. It just doesn’t stop
working). I got frustrated.
How about it? Don’t you feel it nifty?

Of course I can wait for the release next to 2.0.0.
=end

Issue #7877 has been updated by marcandre (Marc-Andre L.).

Note that (thanks to #7715), you can use with_index without a block
and follow it with map:

def leibniz(n)
  (0..Float::INFINITY).lazy.with_index.map {|i, j| (-1 ** j) / 

(2*i+1).to_f }.take(n).reduce(:+)
end

I’m neutral about this feature request. The problem I see is that it’s
too late for 2.0.0 and it would introduce potential incompatibility in
next minor.

Feature #7877: E::Lazy#with_index needed

Author: shyouhei (Shyouhei U.)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: next minor

=begin
So I wanted some real benefit of being lazy. I wrote a Leibniz formula:

def leibniz(n)
(0…Float::INFINITY).lazy.with_index {|i, j| (-1 ** j) /
(2*i+1).to_f }.take(n).reduce(:+)
end

But it doesn’t work (well, it does, indeed. It just doesn’t stop
working). I got frustrated.
How about it? Don’t you feel it nifty?

Of course I can wait for the release next to 2.0.0.
=end

Issue #7877 has been updated by shyouhei (Shyouhei U.).

@marcandre oh, thank you! You saved my day.

Still I want this though.


Feature #7877: E::Lazy#with_index needed

Author: shyouhei (Shyouhei U.)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: next minor

=begin
So I wanted some real benefit of being lazy. I wrote a Leibniz formula:

def leibniz(n)
(0…Float::INFINITY).lazy.with_index {|i, j| (-1 ** j) /
(2*i+1).to_f }.take(n).reduce(:+)
end

But it doesn’t work (well, it does, indeed. It just doesn’t stop
working). I got frustrated.
How about it? Don’t you feel it nifty?

Of course I can wait for the release next to 2.0.0.
=end

Issue #7877 has been updated by zzak (Zachary S.).

Propose to move this to next major?

Feature #7877: E::Lazy#with_index needed

Author: shyouhei (Shyouhei U.)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: next minor

=begin
So I wanted some real benefit of being lazy. I wrote a Leibniz formula:

def leibniz(n)
(0…Float::INFINITY).lazy.with_index {|i, j| (-1 ** j) /
(2*i+1).to_f }.take(n).reduce(:+)
end

But it doesn’t work (well, it does, indeed. It just doesn’t stop
working). I got frustrated.
How about it? Don’t you feel it nifty?

Of course I can wait for the release next to 2.0.0.
=end

Issue #7877 has been updated by marcandre (Marc-Andre L.).

See #7696 on how to handle state…

Feature #7877: E::Lazy#with_index needed

Author: shyouhei (Shyouhei U.)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: next minor

=begin
なんかLazyの有効な例を出そうと思ってそうだライプニッツ級数だ!ということで

def leibniz(n)
(0…Float::INFINITY).lazy.with_index {|i, j| (-1 ** j) /
(2*i+1).to_f }.take(n).reduce(:+)
end

とかやっても動かない(いや動くけど。止まらん)。残念です。これあったほうが便利じゃないですかね。どうでしょう。

あ、もちろん2.0.0以降でOKです。
=end

Issue #7877 has been updated by duerst (Martin Dürst).

zzak (Zachary S.) wrote:

Propose to move this to next major?

Do you mean because of “potential incompatibility”
(Bug #7877: E::Lazy#with_index should be lazy - Ruby master - Ruby Issue Tracking System)? What exactly would this
incompatibility be? To me, it seems that lazy.with_index would just
work, so we should just fix it. Next major seems way too long to wait.

Feature #7877: E::Lazy#with_index needed

Author: shyouhei (Shyouhei U.)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: next minor

=begin
So I wanted some real benefit of being lazy. I wrote a Leibniz formula:

def leibniz(n)
(0…Float::INFINITY).lazy.with_index {|i, j| (-1 ** j) /
(2*i+1).to_f }.take(n).reduce(:+)
end

But it doesn’t work (well, it does, indeed. It just doesn’t stop
working). I got frustrated.
How about it? Don’t you feel it nifty?

Of course I can wait for the release next to 2.0.0.
=end

Issue #7877 has been updated by zzak (Zachary S.).

@duerst You’re probably right, since this feature was introduced in
2.0.0

If yhara-san wants to implement #with_index with a block then I see no
problem with introducing this in 2.1.0

Feature #7877: E::Lazy#with_index needed

Author: shyouhei (Shyouhei U.)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: next minor

=begin
So I wanted some real benefit of being lazy. I wrote a Leibniz formula:

def leibniz(n)
(0…Float::INFINITY).lazy.with_index {|i, j| (-1 ** j) /
(2*i+1).to_f }.take(n).reduce(:+)
end

But it doesn’t work (well, it does, indeed. It just doesn’t stop
working). I got frustrated.
How about it? Don’t you feel it nifty?

Of course I can wait for the release next to 2.0.0.
=end

Issue #7877 has been updated by Hiroshi SHIBATA.

Target version changed from 2.1.0 to current: 2.2.0


Bug #7877: E::Lazy#with_index should be lazy

  • Author: Shyouhei U.
  • Status: Assigned
  • Priority: Normal
  • Assignee: Yutaka HARA
  • Category: core
  • Target version: current: 2.2.0
  • ruby -v: 2.1.0-dev
  • Backport: 2.0.0: UNKNOWN

=begin
So I wanted some real benefit of being lazy. I wrote a Leibniz formula:

def leibniz(n)
(0…Float::INFINITY).lazy.with_index {|i, j| (-1 ** j) /
(2*i+1).to_f }.take(n).reduce(:+)
end

But it doesn’t work (well, it does, indeed. It just doesn’t stop
working). I got frustrated.
How about it? Don’t you feel it nifty?

Of course I can wait for the release next to 2.0.0.
=end

—Files--------------------------------
0001-enumerator.c-Enumerator-Lazy-with_index.patch (3.33 KB)

Issue #7877 has been updated by zzak (Zachary S.).

Tracker changed from Feature to Bug
Subject changed from E::Lazy#with_index needed to E::Lazy#with_index
should be lazy
Target version changed from next minor to current: 2.1.0
ruby -v set to 2.1.0-dev
Backport set to 2.0.0: UNKNOWN


Bug #7877: E::Lazy#with_index should be lazy

Author: shyouhei (Shyouhei U.)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: current: 2.1.0
ruby -v: 2.1.0-dev
Backport: 2.0.0: UNKNOWN

=begin
So I wanted some real benefit of being lazy. I wrote a Leibniz formula:

def leibniz(n)
(0…Float::INFINITY).lazy.with_index {|i, j| (-1 ** j) /
(2*i+1).to_f }.take(n).reduce(:+)
end

But it doesn’t work (well, it does, indeed. It just doesn’t stop
working). I got frustrated.
How about it? Don’t you feel it nifty?

Of course I can wait for the release next to 2.0.0.
=end

Issue #7877 has been updated by Victor Maslov.

Is it related? ruby - ArgumentError - tried to call lazy take_while without a block - Stack Overflow


Bug #7877: E::Lazy#with_index should be lazy

  • Author: Shyouhei U.
  • Status: Assigned
  • Priority: Normal
  • Assignee: Yutaka HARA
  • Category: core
  • Target version: current: 2.2.0
  • ruby -v: 2.1.0-dev
  • Backport: 2.0.0: UNKNOWN

=begin
So I wanted some real benefit of being lazy. I wrote a Leibniz formula:

def leibniz(n)
(0…Float::INFINITY).lazy.with_index {|i, j| (-1 ** j) /
(2*i+1).to_f }.take(n).reduce(:+)
end

But it doesn’t work (well, it does, indeed. It just doesn’t stop
working). I got frustrated.
How about it? Don’t you feel it nifty?

Of course I can wait for the release next to 2.0.0.
=end

—Files--------------------------------
0001-enumerator.c-Enumerator-Lazy-with_index.patch (3.33 KB)