def do_while(self, condition): """Repeats source as long as condition holds emulating a do while loop. Keyword arguments: condition -- {Function} The condition which determines if the source will be repeated. Returns an observable {Observable} sequence which is repeated as long as the condition holds. """ return Observable.concat([self, Observable.while_do(condition, self)])
def for_in(values, result_mapper) -> ObservableBase: """Concatenates the observable sequences obtained by running the specified result mapper for each element in source. Keyword arguments: values -- A list of values to turn into an observable sequence. result_mapper -- A function to apply to each item in the values list to turn it into an observable sequence. Returns an observable sequence from the concatenated observable sequences. """ return Observable.concat(Iterable.for_each(values, result_mapper))
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 Observable.concat(Enumerable.repeat(self, repeat_count))
def while_do(cls, condition, source): """Repeats source as long as condition holds emulating a while loop. Keyword arguments: :param types.FunctionType condition: The condition which determines if the source will be repeated. :param Observable source: The observable sequence that will be run if the condition function returns true. :returns: An observable sequence which is repeated as long as the condition holds. :rtype: Observable """ source = Observable.from_future(source) return Observable.concat(Enumerable.while_do(condition, source))
def concat(self, *args): """Concatenates all the observable sequences. This takes in either an array or variable arguments to concatenate. 1 - concatenated = xs.concat(ys, zs) 2 - concatenated = xs.concat([ys, zs]) Returns an observable sequence that contains the elements of each given sequence, in sequential order. """ if isinstance(args[0], list): items = args[0] else: items = list(args) items.insert(0, self) return Observable.concat(items)
def while_do(cls, condition, source): """Repeats source as long as condition holds emulating a while loop. Arguments: condition (types.FunctionType): The condition which determines if the source will be repeated. source (Observable): The observable sequence that will be run if the condition function returns True. Returns: (Observable): An observable sequence which is repeated as long as the condition holds. """ source = Observable.from_future(source) return Observable.concat(Enumerable.while_do(condition, source))
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. """ if isinstance(args[0], Scheduler): scheduler = args[0] args = args[1:] else: scheduler = kw.get("scheduler", immediate_scheduler) sequence = [Observable.from_(args, scheduler), self] return Observable.concat(sequence)