cgarciae / stop_iter

Apache License 2.0
7 stars 0 forks source link

support decorator and context manager #3

Closed cgarciae closed 3 months ago

cgarciae commented 4 months ago

Now also works as a context manager:

with stop_iter() as it:
  for n in integers():
    print(n)
    if it.interrupt:
      break

And as a decorator:

@(it := stop_iter())
def print_integers():
  for n in integers():
    print(n)
    if it.interrupt:
      break

print_integers()