Пример #1
0
    def slice(source: Observable) -> Observable:
        """The partially applied slice operator.

        Slices the given observable. It is basically a wrapper around the operators
        :func:`skip <rx.operators.skip>`,
        :func:`skip_last <rx.operators.skip_last>`,
        :func:`take <rx.operators.take>`,
        :func:`take_last <rx.operators.take_last>` and
        :func:`filter <rx.operators.filter>`.

        The following diagram helps you remember how slices works with streams.
        Positive numbers are relative to the start of the events, while negative
        numbers are relative to the end (close) of the stream.

        .. code::

            r---e---a---c---t---i---v---e---!
            0   1   2   3   4   5   6   7   8
           -8  -7  -6  -5  -4  -3  -2  -1   0

        Examples:
            >>> result = source.slice(1, 10)
            >>> result = source.slice(1, -2)
            >>> result = source.slice(1, -1, 2)

        Args:
            source: Observable to slice

        Returns:
            A sliced observable sequence.
        """

        if has_stop and _stop >= 0:
            pipeline.append(ops.take(_stop))

        if has_start and _start > 0:
            pipeline.append(ops.skip(_start))

        if has_start and _start < 0:
            pipeline.append(ops.take_last(abs(_start)))

        if has_stop and _stop < 0:
            pipeline.append(ops.skip_last(abs(_stop)))

        if has_step:
            if _step > 1:
                pipeline.append(
                    ops.filter_indexed(lambda x, i: i % _step == 0))
            elif _step < 0:
                # Reversing events is not supported
                raise TypeError('Negative step not supported.')

        return source.pipe(*pipeline)
Пример #2
0
    def slice(source: Observable) -> Observable:
        """The partially applied slice operator.

        Slices the given observable. It is basically a wrapper around the
        operators skip(), skip_last(), take(), take_last() and filter().

        This marble diagram helps you remember how slices works with streams.
        Positive numbers is relative to the start of the events, while negative
        numbers are relative to the end (close) of the stream.

         r---e---a---c---t---i---v---e---|
         0   1   2   3   4   5   6   7   8
        -8  -7  -6  -5  -4  -3  -2  -1   0

        Examples:
            >>> result = source.slice(1, 10)
            >>> result = source.slice(1, -2)
            >>> result = source.slice(1, -1, 2)

        Args:
            source: Observable to slice

        Returns:
            A sliced observable sequence.
        """

        if has_stop and stop >= 0:
            pipeline.append(ops.take(stop))

        if has_start and start > 0:
            pipeline.append(ops.skip(start))

        if has_start and start < 0:
            pipeline.append(ops.take_last(abs(start)))

        if has_stop and stop < 0:
            pipeline.append(ops.skip_last(abs(stop)))

        if has_step:
            if step > 1:
                pipeline.append(ops.filter_indexed(lambda x, i: i % step == 0))
            elif step < 0:
                # Reversing events is not supported
                raise TypeError("Negative step not supported.")

        return source.pipe(*pipeline)
Пример #3
0
    def slice(source: Observable) -> Observable:
        """The partially applied slice operator.

        Slices the given observable. It is basically a wrapper around the
        operators skip(), skip_last(), take(), take_last() and filter().

        This marble diagram helps you remember how slices works with streams.
        Positive numbers is relative to the start of the events, while negative
        numbers are relative to the end (close) of the stream.

         r---e---a---c---t---i---v---e---|
         0   1   2   3   4   5   6   7   8
        -8  -7  -6  -5  -4  -3  -2  -1   0

        Examples:
            >>> result = source.slice(1, 10)
            >>> result = source.slice(1, -2)
            >>> result = source.slice(1, -1, 2)

        Args:
            source: Observable to slice

        Returns:
            A sliced observable sequence.
        """

        if has_stop and stop >= 0:
            pipeline.append(ops.take(stop))

        if has_start and start > 0:
            pipeline.append(ops.skip(start))

        if has_start and start < 0:
            pipeline.append(ops.take_last(abs(start)))

        if has_stop and stop < 0:
            pipeline.append(ops.skip_last(abs(stop)))

        if has_step:
            if step > 1:
                pipeline.append(ops.filter_indexed(lambda x, i: i % step == 0))
            elif step < 0:
                # Reversing events is not supported
                raise TypeError("Negative step not supported.")

        return source.pipe(*pipeline)
Пример #4
0
import rx
import rx.operators as ops

numbers = rx.from_([1, 2, 3, 4, 5, 6])
numbers.pipe(ops.skip_last(2)).subscribe(
    on_next=lambda i: print("on_next {}".format(i)),
    on_error=lambda e: print("on_error: {}".format(e)),
    on_completed=lambda: print("on_completed"))
Пример #5
0
 def create():
     return xs.pipe(ops.skip_last(1))
op.buffer()
op.group_by()
op.map()
op.scan()
# ...

"""Filtering"""
op.debounce()
op.distinct()
op.filter()
op.element_at()
op.first()
op.ignore_elements()
op.last()
op.skip()
op.skip_last()
op.take()
op.take_last()
# ...

"""Error Handling"""
op.catch()
op.retry()

"""Utility"""
op.delay()
op.materialize()
op.time_interval()
op.timeout()
op.timestamp()