[#83773] [Ruby trunk Bug#14108] Seg Fault with MinGW on svn 60769 — usa@...
Issue #14108 has been updated by usa (Usaku NAKAMURA).
9 messages
2017/11/15
[#83774] Re: [Ruby trunk Bug#14108] Seg Fault with MinGW on svn 60769
— Eric Wong <normalperson@...>
2017/11/15
usa@garbagecollect.jp wrote:
[#83775] Re: [Ruby trunk Bug#14108] Seg Fault with MinGW on svn 60769
— "U.NAKAMURA" <usa@...>
2017/11/15
Hi, Eric
[#83779] Re: [Ruby trunk Bug#14108] Seg Fault with MinGW on svn 60769
— Eric Wong <normalperson@...>
2017/11/15
"U.NAKAMURA" <usa@garbagecollect.jp> wrote:
[#83781] Re: [Ruby trunk Bug#14108] Seg Fault with MinGW on svn 60769
— "U.NAKAMURA" <usa@...>
2017/11/15
Hi, Eric,
[#83782] Re: [Ruby trunk Bug#14108] Seg Fault with MinGW on svn 60769
— Eric Wong <normalperson@...>
2017/11/15
"U.NAKAMURA" <usa@garbagecollect.jp> wrote:
[ruby-core:83689] [Ruby trunk Feature#14084] Introduce Enumerator#next?
From:
philipp@...
Date:
2017-11-06 15:28:56 UTC
List:
ruby-core #83689
Issue #14084 has been updated by tessi (Philipp Tessenow).
Description updated
edited the code example to be a little more readable as to michael's suggestion (https://twitter.com/__michaelg/status/927541360764342272)
----------------------------------------
Feature #14084: Introduce Enumerator#next?
https://bugs.ruby-lang.org/issues/14084#change-67715
* Author: tessi (Philipp Tessenow)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
I'd like to propose a new method for Enumerator which returns whether there will be a next value in the enumerator when calling `Enumerator#next`.
It should work like this ruby demo:
~~~ ruby
class Enumerator
def next?
peek
true
rescue StopIteration
false
end
end
a = [1,2,3]
e = a.to_enum
p e.next? #=> true
p e.next #=> 1
p e.next? #=> true
p e.next #=> 2
p e.next? #=> true
p e.next #=> 3
p e.next? #=> false
p e.next #raises StopIteration
~~~
I propose the method to be called `next?` as it returns either `true` or `false`.
I am aware that we can currently figure out if there is a next value by using `rescue` (as in the code snippet above), but it is ugly since it covers many lines and uses exceptions for control flow.
Introducing the `next?` method makes enumerators a little nicer to work with.
A patch with an example implementation for ruby trunk is attached (in git-diff format, any feedback welcome).
I agree that my patch will be licensed under the Ruby License.
---Files--------------------------------
enumerator_next.diff (2.26 KB)
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>