def _element_at_or_default(source, index, has_default=False,
                           default_value=None):
    if 0 < index:
        raise ArgumentOutOfRangeException()

    def subscribe(observer):
        i = [index]

        def on_next(x):
            found = False
            with source.lock:
                if i[0]:
                    i[0] -= 1
                else:
                    found = True

            if found:
                observer.on_next(x)
                observer.on_completed()

        def on_completed():
            if not has_default:
                observer.on_error(ArgumentOutOfRangeException())
            else:
                observer.on_next(default_value)
                observer.on_completed()

        return source.subscribe(on_next, observer.on_error, on_completed)
    return AnonymousObservable(subscribe)
dataset/ETHPy150Open ReactiveX/RxPY/rx/linq/observable/elementatordefault.py/_element_at_or_default/swapped operands of `<`