Utility Classes :: YieldSeq

Overview

YieldSeq() was dreamed up as a solution to the problem of wanting your generator to return objects of different types on sequential yields. Without YieldSeq(), nasty, imprecise workarounds are required:

@yields(IsOneOf(int, float))
def foo():
	yield 5
	yield 5.0
	yield 6
	yield 6.0

Where IsOneOf() is the IsOneOf utility class.

With the YieldSeq() utility class in hand, however, you can express this in a much more type-safe way:

@yields(YieldSeq(int, float, int, float))
def foo():
	yield 5
	yield 5.0
	yield 6
	yield 6.0

This approach is better because it retains a higher degree of precision as opposed to the IsOneOf()-based approach.

Details

Valid XHTML 1.0 Transitional