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

Implement return value from yield() #1397

Open
Spooner opened this Issue Feb 19, 2015 · 1 comment

Comments

Projects
None yet
3 participants
@Spooner
Contributor

Spooner commented Feb 19, 2015

To create generator functions, we need yield(value) to be implemented. This would act like yield(), but 'value' would be passed back and returned from the resume() call.

This would allow range() to be made into an iterator, rather than creating a potentially huge array.

This would also be a step towards nice features like list/dict comprehension.

@jamie-pate

This comment has been minimized.

Show comment
Hide comment
@jamie-pate

jamie-pate May 29, 2018

Unpleasant workaround:

func xrange(count, dict):
	var i = 0
	while i < count:
 		dict.next = i
		yield()
		i += 1

func do_stuff():
	var curr = {}
	var it = xrange(5, curr)
	while curr.value != null:
		print(curr.value)
		it.resume()

jamie-pate commented May 29, 2018

Unpleasant workaround:

func xrange(count, dict):
	var i = 0
	while i < count:
 		dict.next = i
		yield()
		i += 1

func do_stuff():
	var curr = {}
	var it = xrange(5, curr)
	while curr.value != null:
		print(curr.value)
		it.resume()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment