<s> from rx . observable import Observable <EOL> from rx . anonymousobservable import AnonymousObservable <EOL> from rx . internal import extensionmethod <EOL> def find_value ( source , predicate , yield_index ) : <EOL> def subscribe ( observer ) : <EOL> i = [ <NUM_LIT:0> ] <EOL> def on_next ( x ) : <EOL> should_run = False <EOL> try : <EOL> should_run = predicate ( x , i , source ) <EOL> except Exception as ex : <EOL> observer . on_error ( ex ) <EOL> return <EOL> if should_run : <EOL> observer . on_next ( i [ <NUM_LIT:0> ] if yield_index else x ) <EOL> observer . on_completed ( ) <EOL> else : <EOL> i [ <NUM_LIT:0> ] += <NUM_LIT:1> <EOL> def on_completed ( ) : <EOL> observer . on_next ( - <NUM_LIT:1> if yield_index else None ) <EOL> observer . on_completed ( ) <EOL> return source . subscribe ( on_next , observer . on_error , on_completed ) <EOL> return AnonymousObservable ( subscribe ) <EOL> @ extensionmethod ( Observable ) <EOL> def find ( self , predicate ) : <EOL> """<STR_LIT>""" <EOL> return find_value ( self , predicate , False ) </s>
