ruby-changes:61012
From: Marc-Andre <ko1@a...>
Date: Wed, 6 May 2020 06:04:42 +0900 (JST)
Subject: [ruby-changes:61012] 7bde98125e (master): Improve documentation for Enumerator#next, next_values, peek and peek_values.
https://git.ruby-lang.org/ruby.git/commit/?id=7bde98125e From 7bde98125e7f99cab6fe80b59189561bf66fcd0e Mon Sep 17 00:00:00 2001 From: Marc-Andre Lafortune <github@m...> Date: Tue, 5 May 2020 17:02:59 -0400 Subject: Improve documentation for Enumerator#next, next_values, peek and peek_values. [DOC] [#16829] diff --git a/enumerator.c b/enumerator.c index 9632b02..cc0cce8 100644 --- a/enumerator.c +++ b/enumerator.c @@ -81,6 +81,14 @@ https://github.com/ruby/ruby/blob/trunk/enumerator.c#L81 * puts e.next # => 3 * puts e.next # raises StopIteration * + * Note that enumeration sequence by +next+, +next_values+, +peek+ and + * +peek_values+ do not affect other non-external + * enumeration methods, unless the underlying iteration method itself has + * side-effect, e.g. IO#each_line. + * + * Moreover, implementation typically uses fibers so performance could be + * slower and exception stacktraces different than expected. + * * You can use this to implement an internal iterator as follows: * * def ext_each(e) @@ -804,6 +812,8 @@ get_next_values(VALUE obj, struct enumerator *e) https://github.com/ruby/ruby/blob/trunk/enumerator.c#L812 * internal position forward. When the position reached at the end, * StopIteration is raised. * + * See class-level notes about external iterators. + * * This method can be used to distinguish <code>yield</code> and <code>yield * nil</code>. * @@ -837,10 +847,6 @@ get_next_values(VALUE obj, struct enumerator *e) https://github.com/ruby/ruby/blob/trunk/enumerator.c#L847 * # yield nil [nil] nil * # yield [1, 2] [[1, 2]] [1, 2] * - * Note that +next_values+ does not affect other non-external enumeration - * methods unless underlying iteration method itself has side-effect, e.g. - * IO#each_line. - * */ static VALUE @@ -894,9 +900,7 @@ ary2sv(VALUE args, int dup) https://github.com/ruby/ruby/blob/trunk/enumerator.c#L900 * p e.next #=> 3 * p e.next #raises StopIteration * - * Note that enumeration sequence by +next+ does not affect other non-external - * enumeration methods, unless the underlying iteration methods itself has - * side-effect, e.g. IO#each_line. + * See class-level notes about external iterators. * */ @@ -926,6 +930,8 @@ enumerator_peek_values(VALUE obj) https://github.com/ruby/ruby/blob/trunk/enumerator.c#L930 * doesn't move the internal position forward. If the position is already at * the end, StopIteration is raised. * + * See class-level notes about external iterators. + * * === Example * * o = Object.new @@ -960,6 +966,8 @@ enumerator_peek_values_m(VALUE obj) https://github.com/ruby/ruby/blob/trunk/enumerator.c#L966 * position forward. If the position is already at the end, StopIteration * is raised. * + * See class-level notes about external iterators. + * * === Example * * a = [1,2,3] -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/