-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
viable workaround before this lands? #12
Comments
Heck, would it be easier to spec then you would write function^ adder(total = 0) {
let increment = 1
let request
while (true) {
switch ((request = yield (total += increment))) {
case undefined:
break
case 'done':
return total
default:
increment = Number(request)
}
}
} |
In no way would adding a ninth kind of function be easier. |
Dropping the first I don't like to add a new kind of function, but I agree we should explore alternative design, because the example codes for the use cases of this proposal always suffer some similar UX problems. Actually I tried some different alternative designs in last year, and it seem the best form is: function *gen(...args) receive (x) { ... } So @Pyrolistical 's code function^ adder(total = 0) {
let increment = 1
let request
while (true) {
switch ((request = yield (total += increment))) {
case undefined:
break
case 'done':
return total
default:
increment = Number(request)
}
}
} would become function* adder(total = 0) receive (request) {
let increment = 1
while (true) {
switch (request) {
case undefined:
break
case 'done':
return total
default:
increment = Number(request)
}
yield (total += increment)
}
} With some modification (drop weird "undefined" case), it could be simplified to: function* adder(total = 0) receive (increment = 1) {
while (true) {
if (increment == 'done') return total
total += Number(increment)
yield total
}
} Concise and easy to understand ;-) I would like to write more details about this alternative design in a separate issue soon. |
if you want the first
.next(0.1)
to work withyield
, you can just wrap the generator and just drop the first.next
on the floorThe text was updated successfully, but these errors were encountered: