Feb-03-2017, 01:46 AM
today i am working on a project that probably should be a coroutine. it takes in a list of strings. it is expected that this list is very long. it can be a tuple (it is not modified). a page of a series of columns is constructed. the order runs down each column until the bottom of the page, then another column is started. as soon as a next column cannot fit on the page, then the page is done and a new page is started and the "next column" is the first column of the new page. for now the whole list is passed to the function and the returned result is a list of pages. each page is a list of strings that make up the formed lines of the page, ready to print. also passed to the function is page geometry info assuming fixed sized characters: page width, page height, and gutter space between columns. i am thinking that the usefulness of this can be expanded if it is a coroutine, or a generator that has data "sent" to it. but i have not seen ... cannot find .. complete examples of this kind of thing (even if the example is something that we would never do as a coroutine). my coroutine would be initialized with that geometry information then given one string at a time. as soon as a page is complete, it would be yielded to the caller. so i am looking for complete (shows both sides, fully ... how data is received and sent) examples (small, not filled with complexity of the example purpose).
a simple example i can imagine is a coroutine that adds all numbers it receives, and yields the running sum. but an example needs to also show the use ... the other end ... the caller.
a simple example i can imagine is a coroutine that adds all numbers it receives, and yields the running sum. but an example needs to also show the use ... the other end ... the caller.