reactivex 4.1.0__py3-none-any.whl → 5.0.0a2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- reactivex/__init__.py +35 -39
- reactivex/_version.py +1 -1
- reactivex/abc/disposable.py +3 -4
- reactivex/abc/observable.py +13 -6
- reactivex/abc/observer.py +2 -1
- reactivex/abc/periodicscheduler.py +7 -6
- reactivex/abc/scheduler.py +10 -9
- reactivex/abc/subject.py +5 -5
- reactivex/disposable/compositedisposable.py +4 -4
- reactivex/disposable/disposable.py +1 -2
- reactivex/disposable/multipleassignmentdisposable.py +2 -3
- reactivex/disposable/refcountdisposable.py +1 -2
- reactivex/disposable/serialdisposable.py +4 -5
- reactivex/disposable/singleassignmentdisposable.py +3 -4
- reactivex/internal/__init__.py +2 -0
- reactivex/internal/basic.py +2 -2
- reactivex/internal/concurrency.py +2 -1
- reactivex/internal/curry.py +59 -0
- reactivex/internal/exceptions.py +7 -12
- reactivex/internal/priorityqueue.py +2 -2
- reactivex/internal/utils.py +3 -2
- reactivex/notification.py +22 -21
- reactivex/observable/case.py +5 -6
- reactivex/observable/catch.py +3 -2
- reactivex/observable/combinelatest.py +4 -5
- reactivex/observable/concat.py +3 -2
- reactivex/observable/connectableobservable.py +7 -7
- reactivex/observable/defer.py +4 -3
- reactivex/observable/empty.py +3 -4
- reactivex/observable/forkjoin.py +5 -5
- reactivex/observable/fromcallback.py +4 -3
- reactivex/observable/fromfuture.py +2 -2
- reactivex/observable/fromiterable.py +4 -3
- reactivex/observable/generate.py +2 -2
- reactivex/observable/generatewithrelativetime.py +4 -3
- reactivex/observable/groupedobservable.py +4 -4
- reactivex/observable/ifthen.py +3 -2
- reactivex/observable/interval.py +1 -4
- reactivex/observable/marbles.py +18 -17
- reactivex/observable/mixins/__init__.py +32 -0
- reactivex/observable/mixins/combination.py +481 -0
- reactivex/observable/mixins/conditional.py +135 -0
- reactivex/observable/mixins/error_handling.py +130 -0
- reactivex/observable/mixins/filtering.py +1119 -0
- reactivex/observable/mixins/mathematical.py +277 -0
- reactivex/observable/mixins/multicasting.py +306 -0
- reactivex/observable/mixins/testing.py +193 -0
- reactivex/observable/mixins/time_based.py +209 -0
- reactivex/observable/mixins/transformation.py +632 -0
- reactivex/observable/mixins/utility.py +811 -0
- reactivex/observable/mixins/windowing.py +688 -0
- reactivex/observable/never.py +2 -2
- reactivex/observable/observable.py +72 -25
- reactivex/observable/onerrorresumenext.py +7 -6
- reactivex/observable/range.py +6 -6
- reactivex/observable/repeat.py +2 -2
- reactivex/observable/returnvalue.py +6 -5
- reactivex/observable/start.py +3 -2
- reactivex/observable/startasync.py +2 -1
- reactivex/observable/throw.py +3 -3
- reactivex/observable/timer.py +12 -12
- reactivex/observable/toasync.py +3 -2
- reactivex/observable/using.py +5 -4
- reactivex/observable/withlatestfrom.py +4 -5
- reactivex/observable/zip.py +7 -6
- reactivex/observer/autodetachobserver.py +4 -4
- reactivex/observer/observer.py +5 -4
- reactivex/observer/scheduledobserver.py +2 -2
- reactivex/operators/__init__.py +162 -208
- reactivex/operators/_all.py +23 -6
- reactivex/operators/_amb.py +88 -75
- reactivex/operators/_asobservable.py +20 -17
- reactivex/operators/_average.py +48 -45
- reactivex/operators/_buffer.py +81 -35
- reactivex/operators/_bufferwithtime.py +29 -9
- reactivex/operators/_bufferwithtimeorcount.py +27 -8
- reactivex/operators/_catch.py +33 -32
- reactivex/operators/_combinelatest.py +28 -20
- reactivex/operators/_concat.py +16 -13
- reactivex/operators/_contains.py +25 -6
- reactivex/operators/_count.py +24 -8
- reactivex/operators/_debounce.py +141 -138
- reactivex/operators/_defaultifempty.py +45 -42
- reactivex/operators/_delay.py +24 -23
- reactivex/operators/_delaysubscription.py +23 -21
- reactivex/operators/_delaywithmapper.py +10 -11
- reactivex/operators/_dematerialize.py +25 -21
- reactivex/operators/_distinct.py +50 -46
- reactivex/operators/_distinctuntilchanged.py +60 -57
- reactivex/operators/_do.py +123 -116
- reactivex/operators/_dowhile.py +3 -2
- reactivex/operators/_elementatordefault.py +57 -33
- reactivex/operators/_exclusive.py +59 -53
- reactivex/operators/_expand.py +82 -77
- reactivex/operators/_filter.py +63 -68
- reactivex/operators/_finallyaction.py +3 -2
- reactivex/operators/_find.py +49 -32
- reactivex/operators/_first.py +18 -11
- reactivex/operators/_firstordefault.py +5 -4
- reactivex/operators/_flatmap.py +89 -83
- reactivex/operators/_forkjoin.py +23 -18
- reactivex/operators/_groupby.py +27 -6
- reactivex/operators/_groupbyuntil.py +8 -5
- reactivex/operators/_groupjoin.py +7 -6
- reactivex/operators/_ignoreelements.py +20 -15
- reactivex/operators/_isempty.py +15 -4
- reactivex/operators/_join.py +6 -5
- reactivex/operators/_last.py +36 -31
- reactivex/operators/_lastordefault.py +8 -8
- reactivex/operators/_map.py +54 -39
- reactivex/operators/_materialize.py +30 -31
- reactivex/operators/_max.py +18 -11
- reactivex/operators/_maxby.py +5 -5
- reactivex/operators/_merge.py +132 -129
- reactivex/operators/_min.py +16 -10
- reactivex/operators/_minby.py +9 -8
- reactivex/operators/_multicast.py +9 -9
- reactivex/operators/_observeon.py +35 -31
- reactivex/operators/_onerrorresumenext.py +2 -1
- reactivex/operators/_pairwise.py +38 -34
- reactivex/operators/_partition.py +80 -73
- reactivex/operators/_pluck.py +4 -3
- reactivex/operators/_publish.py +36 -21
- reactivex/operators/_publishvalue.py +8 -7
- reactivex/operators/_reduce.py +16 -12
- reactivex/operators/_repeat.py +33 -30
- reactivex/operators/_replay.py +9 -9
- reactivex/operators/_retry.py +12 -10
- reactivex/operators/_sample.py +31 -27
- reactivex/operators/_scan.py +41 -39
- reactivex/operators/_sequenceequal.py +8 -7
- reactivex/operators/_single.py +20 -13
- reactivex/operators/_singleordefault.py +6 -5
- reactivex/operators/_skip.py +35 -32
- reactivex/operators/_skiplast.py +38 -34
- reactivex/operators/_skiplastwithtime.py +5 -4
- reactivex/operators/_skipuntil.py +40 -35
- reactivex/operators/_skipuntilwithtime.py +4 -3
- reactivex/operators/_skipwhile.py +65 -44
- reactivex/operators/_skipwithtime.py +50 -46
- reactivex/operators/_slice.py +58 -53
- reactivex/operators/_some.py +48 -47
- reactivex/operators/_startswith.py +17 -15
- reactivex/operators/_subscribeon.py +44 -41
- reactivex/operators/_sum.py +23 -6
- reactivex/operators/_switchlatest.py +71 -69
- reactivex/operators/_take.py +37 -33
- reactivex/operators/_takelast.py +37 -36
- reactivex/operators/_takelastbuffer.py +38 -37
- reactivex/operators/_takelastwithtime.py +60 -56
- reactivex/operators/_takeuntil.py +33 -32
- reactivex/operators/_takeuntilwithtime.py +42 -39
- reactivex/operators/_takewhile.py +108 -100
- reactivex/operators/_takewithtime.py +46 -41
- reactivex/operators/_throttlefirst.py +52 -45
- reactivex/operators/_timeinterval.py +40 -36
- reactivex/operators/_timeout.py +81 -79
- reactivex/operators/_timeoutwithmapper.py +6 -5
- reactivex/operators/_timestamp.py +24 -22
- reactivex/operators/_todict.py +51 -43
- reactivex/operators/_tofuture.py +24 -15
- reactivex/operators/_toiterable.py +33 -27
- reactivex/operators/_tomarbles.py +5 -5
- reactivex/operators/_toset.py +29 -19
- reactivex/operators/_whiledo.py +2 -1
- reactivex/operators/_window.py +100 -99
- reactivex/operators/_windowwithcount.py +56 -54
- reactivex/operators/_windowwithtime.py +95 -79
- reactivex/operators/_windowwithtimeorcount.py +85 -69
- reactivex/operators/_withlatestfrom.py +13 -9
- reactivex/operators/_zip.py +67 -63
- reactivex/operators/connectable/_refcount.py +4 -3
- reactivex/pipe.py +2 -1
- reactivex/run.py +8 -4
- reactivex/scheduler/catchscheduler.py +11 -10
- reactivex/scheduler/currentthreadscheduler.py +2 -3
- reactivex/scheduler/eventloop/asyncioscheduler.py +7 -6
- reactivex/scheduler/eventloop/asynciothreadsafescheduler.py +12 -14
- reactivex/scheduler/eventloop/eventletscheduler.py +4 -4
- reactivex/scheduler/eventloop/geventscheduler.py +4 -4
- reactivex/scheduler/eventloop/ioloopscheduler.py +4 -4
- reactivex/scheduler/eventloop/twistedscheduler.py +4 -4
- reactivex/scheduler/eventloopscheduler.py +9 -12
- reactivex/scheduler/historicalscheduler.py +1 -2
- reactivex/scheduler/immediatescheduler.py +5 -4
- reactivex/scheduler/mainloop/gtkscheduler.py +6 -7
- reactivex/scheduler/mainloop/pygamescheduler.py +4 -4
- reactivex/scheduler/mainloop/qtscheduler.py +6 -6
- reactivex/scheduler/mainloop/tkinterscheduler.py +4 -4
- reactivex/scheduler/mainloop/wxscheduler.py +7 -7
- reactivex/scheduler/newthreadscheduler.py +6 -8
- reactivex/scheduler/periodicscheduler.py +4 -4
- reactivex/scheduler/scheduleditem.py +4 -4
- reactivex/scheduler/scheduler.py +5 -5
- reactivex/scheduler/threadpoolscheduler.py +3 -3
- reactivex/scheduler/timeoutscheduler.py +5 -4
- reactivex/scheduler/trampoline.py +1 -2
- reactivex/scheduler/trampolinescheduler.py +5 -6
- reactivex/scheduler/virtualtimescheduler.py +4 -4
- reactivex/subject/asyncsubject.py +2 -2
- reactivex/subject/behaviorsubject.py +2 -2
- reactivex/subject/innersubscription.py +2 -2
- reactivex/subject/replaysubject.py +8 -8
- reactivex/subject/subject.py +4 -4
- reactivex/testing/coldobservable.py +5 -5
- reactivex/testing/hotobservable.py +6 -6
- reactivex/testing/marbles.py +21 -20
- reactivex/testing/mockdisposable.py +1 -3
- reactivex/testing/mockobserver.py +2 -2
- reactivex/testing/reactivetest.py +2 -2
- reactivex/testing/recorded.py +1 -1
- reactivex/testing/subscription.py +3 -3
- reactivex/testing/testscheduler.py +13 -12
- reactivex/typing.py +25 -14
- {reactivex-4.1.0.dist-info → reactivex-5.0.0a2.dist-info}/METADATA +59 -26
- reactivex-5.0.0a2.dist-info/RECORD +236 -0
- {reactivex-4.1.0.dist-info → reactivex-5.0.0a2.dist-info}/WHEEL +1 -1
- reactivex-4.1.0.dist-info/RECORD +0 -223
- {reactivex-4.1.0.dist-info → reactivex-5.0.0a2.dist-info}/licenses/LICENSE +0 -0
reactivex/operators/_repeat.py
CHANGED
|
@@ -1,42 +1,45 @@
|
|
|
1
|
-
from typing import
|
|
1
|
+
from typing import TypeVar
|
|
2
2
|
|
|
3
3
|
import reactivex
|
|
4
4
|
from reactivex import Observable
|
|
5
|
+
from reactivex.internal import curry_flip
|
|
5
6
|
from reactivex.internal.utils import infinite
|
|
6
7
|
|
|
7
8
|
_T = TypeVar("_T")
|
|
8
9
|
|
|
9
10
|
|
|
11
|
+
@curry_flip
|
|
10
12
|
def repeat_(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
13
|
+
source: Observable[_T],
|
|
14
|
+
repeat_count: int | None = None,
|
|
15
|
+
) -> Observable[_T]:
|
|
16
|
+
"""Repeats the observable sequence a specified number of times.
|
|
17
|
+
If the repeat count is not specified, the sequence repeats
|
|
18
|
+
indefinitely.
|
|
19
|
+
|
|
20
|
+
Examples:
|
|
21
|
+
>>> result = source.pipe(repeat())
|
|
22
|
+
>>> result = repeat()(source)
|
|
23
|
+
>>> result = source.pipe(repeat(42))
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
source: The observable source to repeat.
|
|
27
|
+
repeat_count: Optional number of times to repeat the sequence.
|
|
28
|
+
If not provided, repeats indefinitely.
|
|
29
|
+
|
|
30
|
+
Returns:
|
|
31
|
+
The observable sequence producing the elements of the given
|
|
32
|
+
sequence repeatedly.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
if repeat_count is None:
|
|
36
|
+
gen = infinite()
|
|
37
|
+
else:
|
|
38
|
+
gen = range(repeat_count)
|
|
39
|
+
|
|
40
|
+
return reactivex.defer(
|
|
41
|
+
lambda _: reactivex.concat_with_iterable(source for _ in gen)
|
|
42
|
+
)
|
|
40
43
|
|
|
41
44
|
|
|
42
45
|
__all = ["repeat"]
|
reactivex/operators/_replay.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
from
|
|
1
|
+
from collections.abc import Callable
|
|
2
|
+
from typing import TypeVar
|
|
2
3
|
|
|
3
|
-
from reactivex import ConnectableObservable, Observable, abc
|
|
4
|
+
from reactivex import ConnectableObservable, Observable, abc, typing
|
|
4
5
|
from reactivex import operators as ops
|
|
5
|
-
from reactivex import typing
|
|
6
6
|
from reactivex.subject import ReplaySubject
|
|
7
7
|
from reactivex.typing import Mapper
|
|
8
8
|
|
|
@@ -11,12 +11,12 @@ _TResult = TypeVar("_TResult")
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
def replay_(
|
|
14
|
-
mapper:
|
|
15
|
-
buffer_size:
|
|
16
|
-
window:
|
|
17
|
-
scheduler:
|
|
14
|
+
mapper: Mapper[Observable[_TSource], Observable[_TResult]] | None = None,
|
|
15
|
+
buffer_size: int | None = None,
|
|
16
|
+
window: typing.RelativeTime | None = None,
|
|
17
|
+
scheduler: abc.SchedulerBase | None = None,
|
|
18
18
|
) -> Callable[
|
|
19
|
-
[Observable[_TSource]],
|
|
19
|
+
[Observable[_TSource]], Observable[_TResult] | ConnectableObservable[_TSource]
|
|
20
20
|
]:
|
|
21
21
|
"""Returns an observable sequence that is the result of invoking the
|
|
22
22
|
mapper on a connectable observable sequence that shares a single
|
|
@@ -52,7 +52,7 @@ def replay_(
|
|
|
52
52
|
if mapper:
|
|
53
53
|
|
|
54
54
|
def subject_factory(
|
|
55
|
-
scheduler:
|
|
55
|
+
scheduler: abc.SchedulerBase | None = None,
|
|
56
56
|
) -> ReplaySubject[_TSource]:
|
|
57
57
|
return ReplaySubject(buffer_size, window, scheduler)
|
|
58
58
|
|
reactivex/operators/_retry.py
CHANGED
|
@@ -1,25 +1,30 @@
|
|
|
1
|
-
from typing import
|
|
1
|
+
from typing import TypeVar
|
|
2
2
|
|
|
3
3
|
import reactivex
|
|
4
4
|
from reactivex import Observable
|
|
5
|
+
from reactivex.internal import curry_flip
|
|
5
6
|
from reactivex.internal.utils import infinite
|
|
6
7
|
|
|
7
8
|
_T = TypeVar("_T")
|
|
8
9
|
|
|
9
10
|
|
|
11
|
+
@curry_flip
|
|
10
12
|
def retry_(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
source: Observable[_T],
|
|
14
|
+
retry_count: int | None = None,
|
|
15
|
+
) -> Observable[_T]:
|
|
13
16
|
"""Repeats the source observable sequence the specified number of
|
|
14
17
|
times or until it successfully terminates. If the retry count is
|
|
15
18
|
not specified, it retries indefinitely.
|
|
16
19
|
|
|
17
20
|
Examples:
|
|
18
|
-
>>>
|
|
19
|
-
>>>
|
|
21
|
+
>>> result = source.pipe(retry())
|
|
22
|
+
>>> result = retry()(source)
|
|
23
|
+
>>> result = source.pipe(retry(42))
|
|
20
24
|
|
|
21
25
|
Args:
|
|
22
|
-
|
|
26
|
+
source: The source observable sequence.
|
|
27
|
+
retry_count: Optional number of times to retry the sequence.
|
|
23
28
|
If not provided, retry the sequence indefinitely.
|
|
24
29
|
|
|
25
30
|
Returns:
|
|
@@ -32,10 +37,7 @@ def retry_(
|
|
|
32
37
|
else:
|
|
33
38
|
gen = range(retry_count)
|
|
34
39
|
|
|
35
|
-
|
|
36
|
-
return reactivex.catch_with_iterable(source for _ in gen)
|
|
37
|
-
|
|
38
|
-
return retry
|
|
40
|
+
return reactivex.catch_with_iterable(source for _ in gen)
|
|
39
41
|
|
|
40
42
|
|
|
41
43
|
__all__ = ["retry_"]
|
reactivex/operators/_sample.py
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
from typing import Any,
|
|
1
|
+
from typing import Any, TypeVar, cast
|
|
2
2
|
|
|
3
3
|
import reactivex
|
|
4
4
|
from reactivex import Observable, abc, typing
|
|
5
5
|
from reactivex.disposable import CompositeDisposable
|
|
6
|
+
from reactivex.internal import curry_flip
|
|
6
7
|
|
|
7
8
|
_T = TypeVar("_T")
|
|
8
9
|
|
|
@@ -11,8 +12,8 @@ def sample_observable(
|
|
|
11
12
|
source: Observable[_T], sampler: Observable[Any]
|
|
12
13
|
) -> Observable[_T]:
|
|
13
14
|
def subscribe(
|
|
14
|
-
observer: abc.ObserverBase[_T], scheduler:
|
|
15
|
-
):
|
|
15
|
+
observer: abc.ObserverBase[_T], scheduler: abc.SchedulerBase | None = None
|
|
16
|
+
) -> abc.DisposableBase:
|
|
16
17
|
at_end = False
|
|
17
18
|
has_value = False
|
|
18
19
|
value: _T = cast(_T, None)
|
|
@@ -50,31 +51,34 @@ def sample_observable(
|
|
|
50
51
|
return Observable(subscribe)
|
|
51
52
|
|
|
52
53
|
|
|
54
|
+
@curry_flip
|
|
53
55
|
def sample_(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
56
|
+
source: Observable[_T],
|
|
57
|
+
sampler: typing.RelativeTime | Observable[Any],
|
|
58
|
+
scheduler: abc.SchedulerBase | None = None,
|
|
59
|
+
) -> Observable[_T]:
|
|
60
|
+
"""Samples the observable sequence at each interval.
|
|
61
|
+
|
|
62
|
+
Examples:
|
|
63
|
+
>>> res = source.pipe(sample(1.0))
|
|
64
|
+
>>> res = sample(1.0)(source)
|
|
65
|
+
>>> res = source.pipe(sample(other_observable))
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
source: Source sequence to sample.
|
|
69
|
+
sampler: Interval or observable to sample at.
|
|
70
|
+
scheduler: Scheduler to use.
|
|
71
|
+
|
|
72
|
+
Returns:
|
|
73
|
+
Sampled observable sequence.
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
if isinstance(sampler, abc.ObservableBase):
|
|
77
|
+
return sample_observable(source, sampler)
|
|
78
|
+
else:
|
|
79
|
+
return sample_observable(
|
|
80
|
+
source, reactivex.interval(sampler, scheduler=scheduler)
|
|
81
|
+
)
|
|
78
82
|
|
|
79
83
|
|
|
80
84
|
__all__ = ["sample_"]
|
reactivex/operators/_scan.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
from typing import
|
|
1
|
+
from typing import TypeVar, cast
|
|
2
2
|
|
|
3
3
|
from reactivex import Observable, abc, defer
|
|
4
4
|
from reactivex import operators as ops
|
|
5
|
+
from reactivex.internal import curry_flip
|
|
5
6
|
from reactivex.internal.utils import NotSet
|
|
6
7
|
from reactivex.typing import Accumulator
|
|
7
8
|
|
|
@@ -9,52 +10,53 @@ _T = TypeVar("_T")
|
|
|
9
10
|
_TState = TypeVar("_TState")
|
|
10
11
|
|
|
11
12
|
|
|
13
|
+
@curry_flip
|
|
12
14
|
def scan_(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
source: Observable[_T],
|
|
16
|
+
accumulator: Accumulator[_TState, _T],
|
|
17
|
+
seed: _TState | type[NotSet] = NotSet,
|
|
18
|
+
) -> Observable[_TState]:
|
|
19
|
+
"""Applies an accumulator function over an observable sequence and
|
|
20
|
+
returns each intermediate result.
|
|
21
|
+
|
|
22
|
+
Examples:
|
|
23
|
+
>>> result = source.pipe(scan(lambda acc, x: acc + x, 0))
|
|
24
|
+
>>> result = scan(lambda acc, x: acc + x, 0)(source)
|
|
25
|
+
>>> result = source.pipe(scan(lambda acc, x: acc + x))
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
source: The observable source to scan.
|
|
29
|
+
accumulator: An accumulator function to invoke on each element.
|
|
30
|
+
seed: Optional initial accumulator value.
|
|
31
|
+
|
|
32
|
+
Returns:
|
|
33
|
+
An observable sequence containing the accumulated values.
|
|
34
|
+
"""
|
|
15
35
|
has_seed = seed is not NotSet
|
|
16
36
|
|
|
17
|
-
def
|
|
18
|
-
|
|
37
|
+
def factory(scheduler: abc.SchedulerBase) -> Observable[_TState]:
|
|
38
|
+
has_accumulation = False
|
|
39
|
+
accumulation: _TState = cast(_TState, None)
|
|
19
40
|
|
|
20
|
-
|
|
21
|
-
|
|
41
|
+
def projection(x: _T) -> _TState:
|
|
42
|
+
nonlocal has_accumulation
|
|
43
|
+
nonlocal accumulation
|
|
22
44
|
|
|
23
|
-
|
|
24
|
-
|
|
45
|
+
if has_accumulation:
|
|
46
|
+
accumulation = accumulator(accumulation, x)
|
|
47
|
+
else:
|
|
48
|
+
accumulation = (
|
|
49
|
+
accumulator(cast(_TState, seed), x)
|
|
50
|
+
if has_seed
|
|
51
|
+
else cast(_TState, x)
|
|
52
|
+
)
|
|
53
|
+
has_accumulation = True
|
|
25
54
|
|
|
26
|
-
|
|
27
|
-
source: The observable source to scan.
|
|
55
|
+
return accumulation
|
|
28
56
|
|
|
29
|
-
|
|
30
|
-
An observable sequence containing the accumulated values.
|
|
31
|
-
"""
|
|
57
|
+
return source.pipe(ops.map(projection))
|
|
32
58
|
|
|
33
|
-
|
|
34
|
-
has_accumulation = False
|
|
35
|
-
accumulation: _TState = cast(_TState, None)
|
|
36
|
-
|
|
37
|
-
def projection(x: _T) -> _TState:
|
|
38
|
-
nonlocal has_accumulation
|
|
39
|
-
nonlocal accumulation
|
|
40
|
-
|
|
41
|
-
if has_accumulation:
|
|
42
|
-
accumulation = accumulator(accumulation, x)
|
|
43
|
-
else:
|
|
44
|
-
accumulation = (
|
|
45
|
-
accumulator(cast(_TState, seed), x)
|
|
46
|
-
if has_seed
|
|
47
|
-
else cast(_TState, x)
|
|
48
|
-
)
|
|
49
|
-
has_accumulation = True
|
|
50
|
-
|
|
51
|
-
return accumulation
|
|
52
|
-
|
|
53
|
-
return source.pipe(ops.map(projection))
|
|
54
|
-
|
|
55
|
-
return defer(factory)
|
|
56
|
-
|
|
57
|
-
return scan
|
|
59
|
+
return defer(factory)
|
|
58
60
|
|
|
59
61
|
|
|
60
62
|
__all__ = ["scan_"]
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
from
|
|
1
|
+
from collections.abc import Callable, Iterable
|
|
2
|
+
from typing import TypeVar
|
|
2
3
|
|
|
3
4
|
import reactivex
|
|
4
5
|
from reactivex import Observable, abc, typing
|
|
@@ -9,8 +10,8 @@ _T = TypeVar("_T")
|
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
def sequence_equal_(
|
|
12
|
-
second:
|
|
13
|
-
comparer:
|
|
13
|
+
second: Observable[_T] | Iterable[_T],
|
|
14
|
+
comparer: typing.Comparer[_T] | None = None,
|
|
14
15
|
) -> Callable[[Observable[_T]], Observable[bool]]:
|
|
15
16
|
comparer_ = comparer or default_comparer
|
|
16
17
|
second_ = (
|
|
@@ -43,12 +44,12 @@ def sequence_equal_(
|
|
|
43
44
|
|
|
44
45
|
def subscribe(
|
|
45
46
|
observer: abc.ObserverBase[bool],
|
|
46
|
-
scheduler:
|
|
47
|
-
):
|
|
47
|
+
scheduler: abc.SchedulerBase | None = None,
|
|
48
|
+
) -> abc.DisposableBase:
|
|
48
49
|
donel = [False]
|
|
49
50
|
doner = [False]
|
|
50
|
-
ql:
|
|
51
|
-
qr:
|
|
51
|
+
ql: list[_T] = []
|
|
52
|
+
qr: list[_T] = []
|
|
52
53
|
|
|
53
54
|
def on_next1(x: _T) -> None:
|
|
54
55
|
if len(qr) > 0:
|
reactivex/operators/_single.py
CHANGED
|
@@ -1,25 +1,32 @@
|
|
|
1
|
-
from typing import
|
|
1
|
+
from typing import TypeVar, cast
|
|
2
2
|
|
|
3
|
-
from reactivex import Observable
|
|
3
|
+
from reactivex import Observable
|
|
4
4
|
from reactivex import operators as ops
|
|
5
|
+
from reactivex.internal import curry_flip
|
|
5
6
|
from reactivex.typing import Predicate
|
|
6
7
|
|
|
8
|
+
from ._singleordefault import single_or_default_async_
|
|
9
|
+
|
|
7
10
|
_T = TypeVar("_T")
|
|
8
11
|
|
|
9
12
|
|
|
13
|
+
@curry_flip
|
|
10
14
|
def single_(
|
|
11
|
-
|
|
12
|
-
|
|
15
|
+
source: Observable[_T],
|
|
16
|
+
predicate: Predicate[_T] | None = None,
|
|
17
|
+
) -> Observable[_T]:
|
|
13
18
|
"""Returns the only element of an observable sequence that satisfies the
|
|
14
19
|
condition in the optional predicate, and reports an exception if there
|
|
15
20
|
is not exactly one element in the observable sequence.
|
|
16
21
|
|
|
17
|
-
|
|
18
|
-
>>> res = single()
|
|
19
|
-
>>> res = single(
|
|
22
|
+
Examples:
|
|
23
|
+
>>> res = source.pipe(single())
|
|
24
|
+
>>> res = single()(source)
|
|
25
|
+
>>> res = source.pipe(single(lambda x: x == 42))
|
|
20
26
|
|
|
21
27
|
Args:
|
|
22
|
-
|
|
28
|
+
source: The source observable sequence.
|
|
29
|
+
predicate: [Optional] A predicate function to evaluate for
|
|
23
30
|
elements in the source sequence.
|
|
24
31
|
|
|
25
32
|
Returns:
|
|
@@ -28,12 +35,12 @@ def single_(
|
|
|
28
35
|
"""
|
|
29
36
|
|
|
30
37
|
if predicate:
|
|
31
|
-
return
|
|
38
|
+
return source.pipe(ops.filter(predicate), ops.single())
|
|
32
39
|
else:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
)
|
|
40
|
+
# single_or_default_async_(False) returns
|
|
41
|
+
# Callable[[Observable[_T]], Observable[_T]] but the type checker
|
|
42
|
+
# cannot infer it. This cast is safe - implementation preserves type.
|
|
43
|
+
return cast(Observable[_T], single_or_default_async_(False)(source))
|
|
37
44
|
|
|
38
45
|
|
|
39
46
|
__all__ = ["single_"]
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
from
|
|
1
|
+
from collections.abc import Callable
|
|
2
|
+
from typing import TypeVar, cast
|
|
2
3
|
|
|
3
4
|
from reactivex import Observable, abc, compose
|
|
4
5
|
from reactivex import operators as ops
|
|
@@ -9,13 +10,13 @@ _T = TypeVar("_T")
|
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
def single_or_default_async_(
|
|
12
|
-
has_default: bool = False, default_value:
|
|
13
|
+
has_default: bool = False, default_value: _T | None = None
|
|
13
14
|
) -> Callable[[Observable[_T]], Observable[_T]]:
|
|
14
15
|
def single_or_default_async(source: Observable[_T]) -> Observable[_T]:
|
|
15
16
|
def subscribe(
|
|
16
17
|
observer: abc.ObserverBase[_T],
|
|
17
|
-
scheduler:
|
|
18
|
-
):
|
|
18
|
+
scheduler: abc.SchedulerBase | None = None,
|
|
19
|
+
) -> abc.DisposableBase:
|
|
19
20
|
value = cast(_T, default_value)
|
|
20
21
|
seen_value = False
|
|
21
22
|
|
|
@@ -47,7 +48,7 @@ def single_or_default_async_(
|
|
|
47
48
|
|
|
48
49
|
|
|
49
50
|
def single_or_default_(
|
|
50
|
-
predicate:
|
|
51
|
+
predicate: Predicate[_T] | None = None, default_value: _T = None
|
|
51
52
|
) -> Callable[[Observable[_T]], Observable[_T]]:
|
|
52
53
|
"""Returns the only element of an observable sequence that matches
|
|
53
54
|
the predicate, or a default value if no such element exists this
|
reactivex/operators/_skip.py
CHANGED
|
@@ -1,50 +1,53 @@
|
|
|
1
|
-
from typing import
|
|
1
|
+
from typing import TypeVar
|
|
2
2
|
|
|
3
3
|
from reactivex import Observable, abc
|
|
4
|
-
from reactivex.internal import ArgumentOutOfRangeException
|
|
4
|
+
from reactivex.internal import ArgumentOutOfRangeException, curry_flip
|
|
5
5
|
|
|
6
6
|
_T = TypeVar("_T")
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def skip(source: Observable[_T]) -> Observable[_T]:
|
|
14
|
-
"""The skip operator.
|
|
9
|
+
@curry_flip
|
|
10
|
+
def skip_(source: Observable[_T], count: int) -> Observable[_T]:
|
|
11
|
+
"""Bypasses a specified number of elements in an observable sequence
|
|
12
|
+
and then returns the remaining elements.
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
Examples:
|
|
15
|
+
>>> result = source.pipe(skip(5))
|
|
16
|
+
>>> result = skip(5)(source)
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
Args:
|
|
19
|
+
source: The source observable.
|
|
20
|
+
count: The number of elements to skip.
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"""
|
|
22
|
+
Returns:
|
|
23
|
+
An observable sequence that contains the elements that occur
|
|
24
|
+
after the specified index in the input sequence.
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
Raises:
|
|
27
|
+
ArgumentOutOfRangeException: If count is negative.
|
|
28
|
+
"""
|
|
29
|
+
if count < 0:
|
|
30
|
+
raise ArgumentOutOfRangeException()
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
def subscribe(
|
|
33
|
+
observer: abc.ObserverBase[_T],
|
|
34
|
+
scheduler: abc.SchedulerBase | None = None,
|
|
35
|
+
) -> abc.DisposableBase:
|
|
36
|
+
remaining = count
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
else:
|
|
39
|
-
remaining -= 1
|
|
38
|
+
def on_next(value: _T) -> None:
|
|
39
|
+
nonlocal remaining
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
if remaining <= 0:
|
|
42
|
+
observer.on_next(value)
|
|
43
|
+
else:
|
|
44
|
+
remaining -= 1
|
|
44
45
|
|
|
45
|
-
return
|
|
46
|
+
return source.subscribe(
|
|
47
|
+
on_next, observer.on_error, observer.on_completed, scheduler=scheduler
|
|
48
|
+
)
|
|
46
49
|
|
|
47
|
-
return
|
|
50
|
+
return Observable(subscribe)
|
|
48
51
|
|
|
49
52
|
|
|
50
53
|
__all__ = ["skip_"]
|
reactivex/operators/_skiplast.py
CHANGED
|
@@ -1,52 +1,56 @@
|
|
|
1
|
-
from typing import
|
|
1
|
+
from typing import TypeVar
|
|
2
2
|
|
|
3
3
|
from reactivex import Observable, abc
|
|
4
|
+
from reactivex.internal import curry_flip
|
|
4
5
|
|
|
5
6
|
_T = TypeVar("_T")
|
|
6
7
|
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
@curry_flip
|
|
10
|
+
def skip_last_(source: Observable[_T], count: int) -> Observable[_T]:
|
|
11
|
+
"""Bypasses a specified number of elements at the end of an
|
|
12
|
+
observable sequence.
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
This operator accumulates a queue with a length enough to store
|
|
15
|
+
the first `count` elements. As more elements are received,
|
|
16
|
+
elements are taken from the front of the queue and produced on
|
|
17
|
+
the result sequence. This causes elements to be delayed.
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
Examples:
|
|
20
|
+
>>> res = source.pipe(skip_last(5))
|
|
21
|
+
>>> res = skip_last(5)(source)
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
Args:
|
|
24
|
+
source: Source observable.
|
|
25
|
+
count: Number of elements to bypass at the end of the
|
|
26
|
+
source sequence.
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
q: List[_T] = []
|
|
28
|
+
Returns:
|
|
29
|
+
An observable sequence containing the source sequence
|
|
30
|
+
elements except for the bypassed ones at the end.
|
|
31
|
+
"""
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
front = q.pop(0)
|
|
33
|
+
def subscribe(
|
|
34
|
+
observer: abc.ObserverBase[_T],
|
|
35
|
+
scheduler: abc.SchedulerBase | None = None,
|
|
36
|
+
) -> abc.DisposableBase:
|
|
37
|
+
q: list[_T] = []
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
def on_next(value: _T) -> None:
|
|
40
|
+
front = None
|
|
41
|
+
with source.lock:
|
|
42
|
+
q.append(value)
|
|
43
|
+
if len(q) > count:
|
|
44
|
+
front = q.pop(0)
|
|
42
45
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
)
|
|
46
|
+
if front is not None:
|
|
47
|
+
observer.on_next(front)
|
|
46
48
|
|
|
47
|
-
return
|
|
49
|
+
return source.subscribe(
|
|
50
|
+
on_next, observer.on_error, observer.on_completed, scheduler=scheduler
|
|
51
|
+
)
|
|
48
52
|
|
|
49
|
-
return
|
|
53
|
+
return Observable(subscribe)
|
|
50
54
|
|
|
51
55
|
|
|
52
56
|
__all__ = ["skip_last_"]
|