def factory(): def predicate(x): nonlocal invoked invoked += 1 return is_prime(x) return xs.pipe(ops.take_while(predicate))
def factory(): def predicate(x): nonlocal invoked invoked += 1 if invoked == 3: raise Exception(ex) return is_prime(x) return xs.pipe(ops.take_while(predicate))