[ruby-dev:48412] [ruby-trunk - Bug #7877] E::Lazy#with_index should be lazy
From:
nakilon@...
Date:
2014-07-16 14:03:04 UTC
List:
ruby-dev #48412
Issue #7877 has been updated by Victor Maslov.
Is it related? http://stackoverflow.com/q/24782712/322020
----------------------------------------
Bug #7877: E::Lazy#with_index should be lazy
https://bugs.ruby-lang.org/issues/7877#change-47808
* Author: Shyouhei Urabe
* 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)
--
https://bugs.ruby-lang.org/