[ruby-dev:50831] [Ruby master Bug#7877] E::Lazy#with_index should be lazy
From:
nobu@...
Date:
2019-08-09 08:07:19 UTC
List:
ruby-dev #50831
Issue #7877 has been updated by nobu (Nobuyoshi Nakada).
Assignee changed from nobu (Nobuyoshi Nakada) to jeremyevans0 (Jeremy Evans)
Description updated
Thank you, I've missed it.
----------------------------------------
Bug #7877: E::Lazy#with_index should be lazy
https://bugs.ruby-lang.org/issues/7877#change-80515
* Author: shyouhei (Shyouhei Urabe)
* Status: Assigned
* Priority: Normal
* Assignee: jeremyevans0 (Jeremy Evans)
* Target version:
* ruby -v: 2.1.0-dev
* Backport: 2.0.0: UNKNOWN
----------------------------------------
So I wanted some real benefit of being lazy. I wrote a Leibniz formula:
```ruby
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.
---Files--------------------------------
0001-enumerator.c-Enumerator-Lazy-with_index.patch (3.33 KB)
lazy-with-index-block-7877.patch (4.08 KB)
--
https://bugs.ruby-lang.org/