Skip to content
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

Generator or Stream should define hasNext (can leverage atEnd) so they can be used with AsyncIteratorStream #4299

Open
botwhytho opened this issue Feb 9, 2025 · 0 comments

Comments

@botwhytho
Copy link

By defining Generator>>#hasNext, one can use that class to feed an async stream.

Something like below on the class hierarchy would be useful

hasNext
	^ self atEnd not

Some example code that makes use of Generator after that change was added locally.

nums := 1 to: 42.
counter := 0.
generator := Generator
		on: [ :gen | 
			[ counter := counter + 1.
			gen yield: (nums atWrap: counter) ] repeat ].
list := BrSimpleList new
		itemStencil: [ BrLabel new
				aptitude: BrGlamorousLabelAptitude new
						+ (BrStyleCommonAptitude new
								selected: [ :aStyle | aStyle background: Color veryVeryLightGray ]);
				padding: (BlInsets all: 5) ];
		itemDataBinder: [ :eachElement :eachInteger :eachIndex | eachElement text: eachInteger asString ];
		stream: (AsyncIteratorStream forIterator: generator)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant