def of(*args: Any) -> ObservableBase: """This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments. Example: res = rx.Observable.of(1,2,3) Returns the observable sequence whose elements are pulled from the given arguments """ return Observable.from_iterable(args)
def start_with(source: ObservableBase, *args: Any) -> ObservableBase: """Prepends a sequence of values to an observable sequence. 1 - source.start_with(1, 2, 3) Returns the source sequence prepended with the specified values. """ start = Observable.from_iterable(args) sequence = [start, source] return concat(*sequence)
def merge_(*args): """Merges all the observable sequences into a single observable sequence. 1 - merged = rx.Observable.merge(xs, ys, zs) 2 - merged = rx.Observable.merge([xs, ys, zs]) Returns the observable sequence that merges the elements of the observable sequences. """ sources = args[:] if isinstance(sources[0], list): sources = sources[0] return Observable.from_iterable(sources).merge_all()
def action1(scheduler, state): xs[0] = Observable.from_iterable(["alpha", "apple", "beta", "bat", "gamma"]) \ .group_by(lambda s: s[0]) \ .map(lambda xs: xs.to_iterable()) \ .merge_all()
def sequence_equal( source, second: ObservableBase, comparer: Callable[[Any, Any], bool] = None) -> ObservableBase: """Determines whether two sequences are equal by comparing the elements pairwise using a specified equality comparer. 1 - res = source.sequence_equal([1,2,3]) 2 - res = source.sequence_equal([{ "value": 42 }], lambda x, y: x.value == y.value) 3 - res = source.sequence_equal(Observable.return_value(42)) 4 - res = source.sequence_equal(Observable.return_value({ "value": 42 }), lambda x, y: x.value == y.value) second -- Second observable sequence or array to compare. comparer -- [Optional] Comparer used to compare elements of both sequences. No guarantees on order of comparer arguments. Returns an observable sequence that contains a single element which indicates whether both sequences are of equal length and their corresponding elements are equal according to the specified equality comparer. """ first = source comparer = comparer or default_comparer if isinstance(second, collections.abc.Iterable): second = Observable.from_iterable(second) def subscribe(observer, scheduler=None): donel = [False] doner = [False] ql = [] qr = [] def on_next1(x): if len(qr) > 0: v = qr.pop(0) try: equal = comparer(v, x) except Exception as e: observer.on_error(e) return if not equal: observer.on_next(False) observer.on_completed() elif doner[0]: observer.on_next(False) observer.on_completed() else: ql.append(x) def on_completed1(): donel[0] = True if not len(ql): if len(qr) > 0: observer.on_next(False) observer.on_completed() elif doner[0]: observer.on_next(True) observer.on_completed() def on_next2(x): if len(ql) > 0: v = ql.pop(0) try: equal = comparer(v, x) except Exception as exception: observer.on_error(exception) return if not equal: observer.on_next(False) observer.on_completed() elif donel[0]: observer.on_next(False) observer.on_completed() else: qr.append(x) def on_completed2(): doner[0] = True if not len(qr): if len(ql) > 0: observer.on_next(False) observer.on_completed() elif donel[0]: observer.on_next(True) observer.on_completed() subscription1 = first.subscribe_(on_next1, observer.on_error, on_completed1, scheduler) subscription2 = second.subscribe_(on_next2, observer.on_error, on_completed2, scheduler) return CompositeDisposable(subscription1, subscription2) return AnonymousObservable(subscribe)
def perform(self, request: SearchRequest): seeya_request = SeeyaSearchRequestMapper().map(request) return (Observable.from_iterable( self.providers).flat_map(lambda x: self.prepare(x, seeya_request)). to_blocking().to_iterable())