def _retry(retry_count: int = None) -> Callable[[Observable], Observable]: """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. Examples: >>> retried = retry() >>> retried = retry(42) Args: 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. """ if retry_count is None: gen = infinite() else: gen = range(retry_count) def retry(source: Observable) -> Observable: return rx.catch(source for _ in gen) return retry
def _retry(retry_count: Optional[int] = None) -> Callable[[Observable], Observable]: """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. Examples: >>> retried = retry() >>> retried = retry(42) Args: 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. """ if retry_count is None: gen = infinite() else: gen = range(retry_count) def retry(source: Observable) -> Observable: return rx.catch_with_iterable(source for _ in gen) return retry
def _map_indexed(mapper_indexed: MapperIndexed = None) -> Callable[[Observable], Observable]: def _identity(value: Any, index: int) -> Any: return value _mapper_indexed = mapper_indexed or _identity return pipe( ops.zip_with_iterable(infinite()), ops.starmap(_mapper_indexed) )
def while_do(source: Observable) -> Observable: """Repeats source as long as condition holds emulating a while loop. Args: 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. """ source = rx.from_future(source) if is_future(source) else source return rx.concat( itertools.takewhile(condition, (source for x in infinite())))
def while_do(source: Union[Observable, Future]) -> Observable: """Repeats source as long as condition holds emulating a while loop. Args: 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. """ if is_future(source): obs = rx.from_future(cast(Future, source)) else: obs = cast(Observable, source) it = itertools.takewhile(condition, (obs for _ in infinite())) return rx.concat_with_iterable(it)
def repeat(source: Observable) -> Observable: """Repeats the observable sequence a specified number of times. If the repeat count is not specified, the sequence repeats indefinitely. Examples: >>> repeated = source.repeat() >>> repeated = source.repeat(42) Args: source: The observable source to repeat. Returns: The observable sequence producing the elements of the given sequence repeatedly. """ if repeat_count is None: gen = infinite() else: gen = range(repeat_count) return rx.defer(lambda _: rx.concat_with_iterable(source for _ in gen))
def while_do(source: Observable) -> Observable: """Repeats source as long as condition holds emulating a while loop. Args: 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. """ source = rx.from_future(source) if is_future(source) else source return rx.concat_with_iterable(itertools.takewhile(condition, (source for x in infinite())))