def while_do(cls, condition, source): def next(): while condition(source): yield source raise StopIteration() return Enumerable(next())
def for_in(cls, sources, result_selector): """Concatenates the observable sequences obtained by running the specified result selector for each element in source. sources -- {Array} An array of values to turn into an observable sequence. result_selector -- {Function} A function to apply to each item in the sources array to turn it into an observable sequence. Returns an observable {Observable} sequence from the concatenated observable sequences.""" return Observable.concat(Enumerable.for_each(sources, result_selector))
def __repeat(self, repeat_count=None): """Repeats the observable sequence a specified number of times. If the repeat count is not specified, the sequence repeats indefinitely. 1 - repeated = source.repeat() 2 - repeated = source.repeat(42) Keyword arguments: repeat_count -- Number of times to repeat the sequence. If not provided, repeats the sequence indefinitely. Returns the observable sequence producing the elements of the given sequence repeatedly. """ return concat(Enumerable.repeat(self, repeat_count))
def retry(self, retry_count=None): """Repeats the source observable sequence the specified number of times or until it successfully terminates. If the retry count is not specified, it retries indefinitely. 1 - retried = retry.repeat(); 2 - retried = retry.repeat(42); retry_count -- [Optional] Number of times to retry the sequence. If not provided, retry the sequence indefinitely. Returns an observable sequence producing the elements of the given sequence repeatedly until it terminates successfully. """ return catch_exception(Enumerable.repeat(self, retry_count))
def concat(cls, *args): """Concatenates all the observable sequences. 1 - res = Observable.concat(xs, ys, zs) 2 - res = Observable.concat([xs, ys, zs]) Returns an observable sequence that contains the elements of each given sequence, in sequential order. """ if isinstance(args[0], list): sources = args[0] else: sources = list(args) return concat(Enumerable.for_each(sources))
def catch_exception(cls, *args): """Continues an observable sequence that is terminated by an exception with the next observable sequence. 1 - res = Observable.catch_exception(xs, ys, zs) 2 - res = Observable.catch_exception([xs, ys, zs]) Returns an observable sequence containing elements from consecutive source sequences until a source sequence terminates successfully. """ if args and isinstance(args[0], list): items = args[0] else: items = list(args) return catch_exception(Enumerable.for_each(items))
def start_with(self, *args, **kw): """Prepends a sequence of values to an observable sequence with an optional scheduler and an argument list of values to prepend. 1 - source.start_with(1, 2, 3) 2 - source.start_with(Scheduler.timeout, 1, 2, 3) Returns the source sequence prepended with the specified values. """ scheduler = kw.get("scheduler") if not scheduler and isinstance(args[0], Scheduler): scheduler = args.pop(0) else: scheduler = immediate_scheduler sequence = [Observable.from_array(args, scheduler), self] return concat(Enumerable.for_each(sequence))
def start_with(self, *args, **kw): """Prepends a sequence of values to an observable sequence with an optional scheduler and an argument list of values to prepend. 1 - source.start_with(1, 2, 3) 2 - source.start_with(Rx.Scheduler.timeout, 1, 2, 3) Returns the source sequence prepended with the specified values. """ scheduler = kw.get("scheduler") if not scheduler and isinstance(args[0], Scheduler): scheduler = args.pop(0) else: scheduler = immediate_scheduler sequence = [Observable.from_array(args, scheduler), self] return concat(Enumerable.for_each(sequence))