human
Complete the below
def loop_until_state_found(reactor, get_states, state_matches, timeout):

    ''''Loop until a state has been reached.
    :param IReactorTime reactor: Twisted Reactor.
    :param get_states: Callable returning a Deferred firing with a list
    of states.
    :param state_matches: Callable that accepts a state parameter, and
    returns a boolean indicating whether the state matches.
    :param timedelta timeout: Maximum time to wait for state to be found.
    :return Deferred[Any]: The matching state.'
    '''
 Can you provide a the Python program you requested?
assistant
#Here is the Python program you requested.
    def state_reached():
        d = get_states()
        def find_match(states):
            for state in states:
                if state_matches(state):
                    return state
            return None
        d.addCallback(find_match)
        return d
    d = loop_until(reactor, state_reached)
    _timeout(reactor, d, timeout.total_seconds())
    return d