60 lines
1.2 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
A generator without a ``++yield++`` statement is at best confusing, and at worst a bug in your code, since the iterator produced by your code will always be empty.
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,javascript]
2021-04-28 16:49:39 +02:00
----
function* myGen(a, b) { // Noncompliant
let answer = 0;
answer += a * b;
}
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,javascript]
2021-04-28 16:49:39 +02:00
----
function* myGen(a, b) {
let answer = 0;
while (answer < 42) {
answer += a * b;
yield answer;
}
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Add a "yield" statement to this generator.
=== Highlighting
``++function* xxx++``
'''
== Comments And Links
(visible only on this page)
=== on 5 Feb 2016, 15:52:49 Elena Vilchik wrote:
\[~ann.campbell.2] Could you add to description smth like "It even could be a bug in your problem as you your iterator produced by this generator function is always empty"?
And I would like to remove highlighting and specific message for return, I don't think it's worth that. Are you ok?
=== on 5 Feb 2016, 16:06:15 Ann Campbell wrote:
done [~elena.vilchik]
endif::env-github,rspecator-view[]