<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2018-05-11 17:06 GMT+03:00 Clint Hepner <span dir="ltr"><<a href="mailto:clint.hepner@gmail.com" target="_blank">clint.hepner@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-"></span><br>
<br>
(This reminds that I wish ``iter`` could take a predicate instead of a sentinel as its second argument. Then<br>
you could just write<br>
<br>
    for cmd in iter(get_command, lambda x: x.token == CMD_QUIT):<br>
        cmd.do_something()<br>
)<br>
<br></blockquote></div><br></div><div class="gmail_extra">But you can do it right now:<br><br><div style="margin-left:40px"><span style="font-family:monospace,monospace">class P:</span><br><span style="font-family:monospace,monospace">    def __init__(self, key):</span><br><span style="font-family:monospace,monospace">        self.key = key </span><br><span style="font-family:monospace,monospace">    def __eq__(self, other):</span><br><span style="font-family:monospace,monospace">        return self.key(other)<br><br>for cmd in iter(get_command, P(lambda x: x.token == CMD_QUIT)):<br>    cmd.do_something()

<br><br></span></div>With kind regards,<br></div><div class="gmail_extra">-gdg<br></div><div class="gmail_extra"><span style="font-family:monospace,monospace"></span></div></div>