mikeshardmind / salamander-v1

Apache License 2.0
6 stars 0 forks source link

Generator use... #15

Closed mikeshardmind closed 3 years ago

mikeshardmind commented 3 years ago

Consideration on generator use: (or equivalent async generator)

Mostly here for me to not forget about this idea later, might decide it's not being added and close this.


class GenCYA(ChooseYourOwnAdventure, Generator):

    def __iter__(self):
        return self

    def send(self, v):
        if v is None:
            try:
                return self.get_prompt()
            except AlreadyDone:
                raise StopIteration
        else:
            self.turn_page(v)
            if self.check_if_done():
                return self.get_result()
            else:
                return self.get_prompt()

    def throw(self, type=None, value=None, traceback=None):
        raise StopIteration
mikeshardmind commented 3 years ago

Won't be doing this. It's neat conceptually but it's not any better than handling it the current way and adds a higher level of understanding needed for potential contributors.

Example above also has a bit of a sharp edge in having the generator yield the result which is allowed to be a different type and may need other handling, if it were ever added, the actual result should be fetched from the consumed generator instead.