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
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
from
|
|
1
|
+
from collections.abc import Callable
|
|
2
|
+
from typing import TypeVar
|
|
2
3
|
|
|
3
4
|
from reactivex import ConnectableObservable, Observable, abc
|
|
4
5
|
from reactivex import operators as ops
|
|
@@ -9,14 +10,13 @@ _TResult = TypeVar("_TResult")
|
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
def multicast_(
|
|
12
|
-
subject:
|
|
13
|
+
subject: abc.SubjectBase[_TSource] | None = None,
|
|
13
14
|
*,
|
|
14
|
-
subject_factory:
|
|
15
|
-
|
|
16
|
-
] = None,
|
|
17
|
-
mapper: Optional[Callable[[Observable[_TSource]], Observable[_TResult]]] = None,
|
|
15
|
+
subject_factory: Callable[[abc.SchedulerBase | None], abc.SubjectBase[_TSource]]
|
|
16
|
+
| None = None,
|
|
17
|
+
mapper: Callable[[Observable[_TSource]], Observable[_TResult]] | None = None,
|
|
18
18
|
) -> Callable[
|
|
19
|
-
[Observable[_TSource]],
|
|
19
|
+
[Observable[_TSource]], Observable[_TResult] | ConnectableObservable[_TSource]
|
|
20
20
|
]:
|
|
21
21
|
"""Multicasts the source sequence notifications through an
|
|
22
22
|
instantiated subject into all uses of the sequence within a mapper
|
|
@@ -50,12 +50,12 @@ def multicast_(
|
|
|
50
50
|
|
|
51
51
|
def multicast(
|
|
52
52
|
source: Observable[_TSource],
|
|
53
|
-
) ->
|
|
53
|
+
) -> Observable[_TResult] | ConnectableObservable[_TSource]:
|
|
54
54
|
if subject_factory:
|
|
55
55
|
|
|
56
56
|
def subscribe(
|
|
57
57
|
observer: abc.ObserverBase[_TResult],
|
|
58
|
-
scheduler:
|
|
58
|
+
scheduler: abc.SchedulerBase | None = None,
|
|
59
59
|
) -> abc.DisposableBase:
|
|
60
60
|
assert subject_factory
|
|
61
61
|
connectable = source.pipe(
|
|
@@ -1,43 +1,47 @@
|
|
|
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
|
from reactivex.observer import ObserveOnObserver
|
|
5
6
|
|
|
6
7
|
_T = TypeVar("_T")
|
|
7
8
|
|
|
8
9
|
|
|
10
|
+
@curry_flip
|
|
9
11
|
def observe_on_(
|
|
12
|
+
source: Observable[_T],
|
|
10
13
|
scheduler: abc.SchedulerBase,
|
|
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
|
-
|
|
40
|
-
|
|
14
|
+
) -> Observable[_T]:
|
|
15
|
+
"""Wraps the source sequence in order to run its observer
|
|
16
|
+
callbacks on the specified scheduler.
|
|
17
|
+
|
|
18
|
+
This only invokes observer callbacks on a scheduler. In case
|
|
19
|
+
the subscription and/or unsubscription actions have
|
|
20
|
+
side-effects that require to be run on a scheduler, use
|
|
21
|
+
subscribe_on.
|
|
22
|
+
|
|
23
|
+
Examples:
|
|
24
|
+
>>> res = source.pipe(observe_on(scheduler))
|
|
25
|
+
>>> res = observe_on(scheduler)(source)
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
source: Source observable.
|
|
29
|
+
scheduler: Scheduler to observe on.
|
|
30
|
+
|
|
31
|
+
Returns:
|
|
32
|
+
Returns the source sequence whose observations happen on
|
|
33
|
+
the specified scheduler.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
def subscribe(
|
|
37
|
+
observer: abc.ObserverBase[_T],
|
|
38
|
+
subscribe_scheduler: abc.SchedulerBase | None = None,
|
|
39
|
+
):
|
|
40
|
+
return source.subscribe(
|
|
41
|
+
ObserveOnObserver(scheduler, observer), scheduler=subscribe_scheduler
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
return Observable(subscribe)
|
|
41
45
|
|
|
42
46
|
|
|
43
47
|
__all__ = ["observe_on_"]
|
reactivex/operators/_pairwise.py
CHANGED
|
@@ -1,53 +1,57 @@
|
|
|
1
|
-
from typing import
|
|
1
|
+
from typing import TypeVar, cast
|
|
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
|
-
|
|
9
|
+
@curry_flip
|
|
10
|
+
def pairwise_(source: Observable[_T]) -> Observable[tuple[_T, _T]]:
|
|
11
|
+
"""Returns a new observable that triggers on the second and
|
|
12
|
+
subsequent triggerings of the input observable. The Nth
|
|
13
|
+
triggering of the input observable passes the arguments from
|
|
14
|
+
the N-1th and Nth triggering as a pair. The argument passed to
|
|
15
|
+
the N-1th triggering is held in hidden internal state until the
|
|
16
|
+
Nth triggering occurs.
|
|
11
17
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
the N-1th and Nth triggering as a pair. The argument passed to
|
|
16
|
-
the N-1th triggering is held in hidden internal state until the
|
|
17
|
-
Nth triggering occurs.
|
|
18
|
+
Examples:
|
|
19
|
+
>>> res = source.pipe(pairwise())
|
|
20
|
+
>>> res = pairwise()(source)
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
observations from the input observable as an array.
|
|
22
|
-
"""
|
|
22
|
+
Args:
|
|
23
|
+
source: The source observable sequence.
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
has_previous = False
|
|
29
|
-
previous: _T = cast(_T, None)
|
|
25
|
+
Returns:
|
|
26
|
+
An observable that triggers on successive pairs of
|
|
27
|
+
observations from the input observable as an array.
|
|
28
|
+
"""
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
def subscribe(
|
|
31
|
+
observer: abc.ObserverBase[tuple[_T, _T]],
|
|
32
|
+
scheduler: abc.SchedulerBase | None = None,
|
|
33
|
+
) -> abc.DisposableBase:
|
|
34
|
+
has_previous = False
|
|
35
|
+
previous: _T = cast(_T, None)
|
|
34
36
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
else:
|
|
39
|
-
has_previous = True
|
|
37
|
+
def on_next(x: _T) -> None:
|
|
38
|
+
nonlocal has_previous, previous
|
|
39
|
+
pair = None
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
with source.lock:
|
|
42
|
+
if has_previous:
|
|
43
|
+
pair = (previous, x)
|
|
44
|
+
else:
|
|
45
|
+
has_previous = True
|
|
42
46
|
|
|
43
|
-
|
|
44
|
-
observer.on_next(pair)
|
|
47
|
+
previous = x
|
|
45
48
|
|
|
46
|
-
|
|
49
|
+
if pair:
|
|
50
|
+
observer.on_next(pair)
|
|
47
51
|
|
|
48
|
-
return
|
|
52
|
+
return source.subscribe(on_next, observer.on_error, observer.on_completed)
|
|
49
53
|
|
|
50
|
-
return
|
|
54
|
+
return Observable(subscribe)
|
|
51
55
|
|
|
52
56
|
|
|
53
57
|
__all__ = ["pairwise_"]
|
|
@@ -1,88 +1,95 @@
|
|
|
1
|
-
from typing import
|
|
1
|
+
from typing import TypeVar
|
|
2
2
|
|
|
3
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, PredicateIndexed
|
|
6
7
|
|
|
7
8
|
_T = TypeVar("_T")
|
|
8
9
|
|
|
9
10
|
|
|
11
|
+
@curry_flip
|
|
10
12
|
def partition_(
|
|
13
|
+
source: Observable[_T],
|
|
11
14
|
predicate: Predicate[_T],
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
15
|
+
) -> list[Observable[_T]]:
|
|
16
|
+
"""Returns two observables which partition the observations of the
|
|
17
|
+
source by the given function.
|
|
18
|
+
|
|
19
|
+
The first will trigger observations for those values for which the
|
|
20
|
+
predicate returns true. The second will trigger observations for
|
|
21
|
+
those values where the predicate returns false. The predicate is
|
|
22
|
+
executed once for each subscribed observer. Both also propagate all
|
|
23
|
+
error observations arising from the source and each completes
|
|
24
|
+
when the source completes.
|
|
25
|
+
|
|
26
|
+
Examples:
|
|
27
|
+
>>> res = source.pipe(partition(lambda x: x > 5))
|
|
28
|
+
>>> res = partition(lambda x: x > 5)(source)
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
source: Source observable to partition.
|
|
32
|
+
predicate: Function to test each element.
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
A list of observables. The first triggers when the
|
|
36
|
+
predicate returns True, and the second triggers when the
|
|
37
|
+
predicate returns False.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
def not_predicate(x: _T) -> bool:
|
|
41
|
+
return not predicate(x)
|
|
42
|
+
|
|
43
|
+
published = source.pipe(
|
|
44
|
+
ops.publish(),
|
|
45
|
+
ops.ref_count(),
|
|
46
|
+
)
|
|
47
|
+
return [
|
|
48
|
+
published.pipe(ops.filter(predicate)),
|
|
49
|
+
published.pipe(ops.filter(not_predicate)),
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@curry_flip
|
|
49
54
|
def partition_indexed_(
|
|
55
|
+
source: Observable[_T],
|
|
50
56
|
predicate_indexed: PredicateIndexed[_T],
|
|
51
|
-
) ->
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
57
|
+
) -> list[Observable[_T]]:
|
|
58
|
+
"""Returns two observables which partition the observations of the
|
|
59
|
+
source by the given indexed function.
|
|
60
|
+
|
|
61
|
+
The first will trigger observations for those values for which the
|
|
62
|
+
predicate returns true. The second will trigger observations for
|
|
63
|
+
those values where the predicate returns false. The predicate is
|
|
64
|
+
executed once for each subscribed observer. Both also propagate all
|
|
65
|
+
error observations arising from the source and each completes
|
|
66
|
+
when the source completes.
|
|
67
|
+
|
|
68
|
+
Examples:
|
|
69
|
+
>>> res = source.pipe(partition_indexed(lambda x, i: i % 2 == 0))
|
|
70
|
+
>>> res = partition_indexed(lambda x, i: i % 2 == 0)(source)
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
source: Source observable to partition.
|
|
74
|
+
predicate_indexed: Function to test each element with its index.
|
|
75
|
+
|
|
76
|
+
Returns:
|
|
77
|
+
A list of observables. The first triggers when the
|
|
78
|
+
predicate returns True, and the second triggers when the
|
|
79
|
+
predicate returns False.
|
|
80
|
+
"""
|
|
81
|
+
|
|
82
|
+
def not_predicate_indexed(x: _T, i: int) -> bool:
|
|
83
|
+
return not predicate_indexed(x, i)
|
|
84
|
+
|
|
85
|
+
published = source.pipe(
|
|
86
|
+
ops.publish(),
|
|
87
|
+
ops.ref_count(),
|
|
88
|
+
)
|
|
89
|
+
return [
|
|
90
|
+
published.pipe(ops.filter_indexed(predicate_indexed)),
|
|
91
|
+
published.pipe(ops.filter_indexed(not_predicate_indexed)),
|
|
92
|
+
]
|
|
86
93
|
|
|
87
94
|
|
|
88
95
|
__all__ = ["partition_", "partition_indexed_"]
|
reactivex/operators/_pluck.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
from
|
|
1
|
+
from collections.abc import Callable
|
|
2
|
+
from typing import Any, TypeVar
|
|
2
3
|
|
|
3
4
|
from reactivex import Observable
|
|
4
5
|
from reactivex import operators as ops
|
|
@@ -9,7 +10,7 @@ _TValue = TypeVar("_TValue")
|
|
|
9
10
|
|
|
10
11
|
def pluck_(
|
|
11
12
|
key: _TKey,
|
|
12
|
-
) -> Callable[[Observable[
|
|
13
|
+
) -> Callable[[Observable[dict[_TKey, _TValue]]], Observable[_TValue]]:
|
|
13
14
|
"""Retrieves the value of a specified key using dict-like access (as in
|
|
14
15
|
element[key]) from all elements in the Observable sequence.
|
|
15
16
|
|
|
@@ -21,7 +22,7 @@ def pluck_(
|
|
|
21
22
|
To pluck an attribute of each element, use pluck_attr.
|
|
22
23
|
"""
|
|
23
24
|
|
|
24
|
-
def mapper(x:
|
|
25
|
+
def mapper(x: dict[_TKey, _TValue]) -> _TValue:
|
|
25
26
|
return x[key]
|
|
26
27
|
|
|
27
28
|
return ops.map(mapper)
|
reactivex/operators/_publish.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
from typing import
|
|
1
|
+
from typing import TypeVar
|
|
2
2
|
|
|
3
3
|
from reactivex import ConnectableObservable, Observable, abc, compose
|
|
4
4
|
from reactivex import operators as ops
|
|
5
|
+
from reactivex.internal import curry_flip
|
|
5
6
|
from reactivex.subject import Subject
|
|
6
7
|
from reactivex.typing import Mapper
|
|
7
8
|
|
|
@@ -9,25 +10,26 @@ _TSource = TypeVar("_TSource")
|
|
|
9
10
|
_TResult = TypeVar("_TResult")
|
|
10
11
|
|
|
11
12
|
|
|
13
|
+
@curry_flip
|
|
12
14
|
def publish_(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
]:
|
|
15
|
+
source: Observable[_TSource],
|
|
16
|
+
mapper: Mapper[Observable[_TSource], Observable[_TResult]] | None = None,
|
|
17
|
+
) -> Observable[_TResult] | ConnectableObservable[_TSource]:
|
|
17
18
|
"""Returns an observable sequence that is the result of invoking the
|
|
18
19
|
mapper on a connectable observable sequence that shares a single
|
|
19
20
|
subscription to the underlying sequence. This operator is a
|
|
20
21
|
specialization of Multicast using a regular Subject.
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
>>>
|
|
24
|
-
>>>
|
|
23
|
+
Examples:
|
|
24
|
+
>>> source.pipe(publish())
|
|
25
|
+
>>> source.pipe(publish(lambda x: x))
|
|
26
|
+
>>> publish()(source)
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
Args:
|
|
29
|
+
source: Source observable to publish.
|
|
30
|
+
mapper: [Optional] Selector function which can use the
|
|
31
|
+
multicasted source sequence as many times as needed, without
|
|
32
|
+
causing multiple subscriptions to the source sequence.
|
|
31
33
|
|
|
32
34
|
Returns:
|
|
33
35
|
An observable sequence that contains the elements of a sequence
|
|
@@ -37,17 +39,18 @@ def publish_(
|
|
|
37
39
|
|
|
38
40
|
if mapper:
|
|
39
41
|
|
|
40
|
-
def factory(scheduler:
|
|
42
|
+
def factory(scheduler: abc.SchedulerBase | None = None) -> Subject[_TSource]:
|
|
41
43
|
return Subject()
|
|
42
44
|
|
|
43
|
-
return ops.multicast(subject_factory=factory, mapper=mapper)
|
|
45
|
+
return source.pipe(ops.multicast(subject_factory=factory, mapper=mapper))
|
|
44
46
|
|
|
45
47
|
subject: Subject[_TSource] = Subject()
|
|
46
|
-
return ops.multicast(subject=subject)
|
|
48
|
+
return source.pipe(ops.multicast(subject=subject))
|
|
47
49
|
|
|
48
50
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
@curry_flip
|
|
52
|
+
def share_(source: Observable[_TSource]) -> Observable[_TSource]:
|
|
53
|
+
"""Share a single subscription among multiple observers.
|
|
51
54
|
|
|
52
55
|
Returns a new Observable that multicasts (shares) the original
|
|
53
56
|
Observable. As long as there is at least one Subscriber this
|
|
@@ -56,10 +59,22 @@ def share_() -> Callable[[Observable[_TSource]], Observable[_TSource]]:
|
|
|
56
59
|
Observable.
|
|
57
60
|
|
|
58
61
|
This is an alias for a composed publish() and ref_count().
|
|
62
|
+
|
|
63
|
+
Examples:
|
|
64
|
+
>>> source.pipe(share())
|
|
65
|
+
>>> share()(source)
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
source: Source observable to share.
|
|
69
|
+
|
|
70
|
+
Returns:
|
|
71
|
+
An observable that shares a single subscription.
|
|
59
72
|
"""
|
|
60
|
-
return
|
|
61
|
-
|
|
62
|
-
|
|
73
|
+
return source.pipe(
|
|
74
|
+
compose(
|
|
75
|
+
ops.publish(),
|
|
76
|
+
ops.ref_count(),
|
|
77
|
+
)
|
|
63
78
|
)
|
|
64
79
|
|
|
65
80
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
from
|
|
1
|
+
from collections.abc import Callable
|
|
2
|
+
from typing import TypeVar
|
|
2
3
|
|
|
3
4
|
from reactivex import ConnectableObservable, Observable, abc
|
|
4
5
|
from reactivex import operators as ops
|
|
@@ -11,15 +12,15 @@ _T2 = TypeVar("_T2")
|
|
|
11
12
|
|
|
12
13
|
def publish_value_(
|
|
13
14
|
initial_value: _T1,
|
|
14
|
-
mapper:
|
|
15
|
-
) ->
|
|
16
|
-
Callable[[Observable[_T1]], ConnectableObservable[_T1]]
|
|
17
|
-
Callable[[Observable[_T1]], Observable[_T2]]
|
|
18
|
-
|
|
15
|
+
mapper: Mapper[Observable[_T1], Observable[_T2]] | None = None,
|
|
16
|
+
) -> (
|
|
17
|
+
Callable[[Observable[_T1]], ConnectableObservable[_T1]]
|
|
18
|
+
| Callable[[Observable[_T1]], Observable[_T2]]
|
|
19
|
+
):
|
|
19
20
|
if mapper:
|
|
20
21
|
|
|
21
22
|
def subject_factory(
|
|
22
|
-
scheduler:
|
|
23
|
+
scheduler: abc.SchedulerBase | None = None,
|
|
23
24
|
) -> BehaviorSubject[_T1]:
|
|
24
25
|
return BehaviorSubject(initial_value)
|
|
25
26
|
|
reactivex/operators/_reduce.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
from typing import Any,
|
|
1
|
+
from typing import Any, 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.internal.utils import NotSet
|
|
6
7
|
from reactivex.typing import Accumulator
|
|
7
8
|
|
|
@@ -9,9 +10,12 @@ _T = TypeVar("_T")
|
|
|
9
10
|
_TState = TypeVar("_TState")
|
|
10
11
|
|
|
11
12
|
|
|
13
|
+
@curry_flip
|
|
12
14
|
def reduce_(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
source: Observable[_T],
|
|
16
|
+
accumulator: Accumulator[_TState, _T],
|
|
17
|
+
seed: _TState | type[NotSet] = NotSet,
|
|
18
|
+
) -> Observable[Any]:
|
|
15
19
|
"""Applies an accumulator function over an observable sequence,
|
|
16
20
|
returning the result of the aggregation as a single element in the
|
|
17
21
|
result sequence. The specified seed value is used as the initial
|
|
@@ -21,28 +25,28 @@ def reduce_(
|
|
|
21
25
|
`scan()`.
|
|
22
26
|
|
|
23
27
|
Examples:
|
|
24
|
-
>>>
|
|
25
|
-
>>>
|
|
28
|
+
>>> result = source.pipe(reduce(lambda acc, x: acc + x))
|
|
29
|
+
>>> result = reduce(lambda acc, x: acc + x)(source)
|
|
30
|
+
>>> result = source.pipe(reduce(lambda acc, x: acc + x, 0))
|
|
26
31
|
|
|
27
32
|
Args:
|
|
28
|
-
|
|
29
|
-
|
|
33
|
+
source: The source observable.
|
|
34
|
+
accumulator: An accumulator function to be invoked on each element.
|
|
30
35
|
seed: Optional initial accumulator value.
|
|
31
36
|
|
|
32
37
|
Returns:
|
|
33
|
-
An
|
|
34
|
-
an observable sequence containing a single element with the
|
|
38
|
+
An observable sequence containing a single element with the
|
|
35
39
|
final accumulator value.
|
|
36
40
|
"""
|
|
37
41
|
if seed is not NotSet:
|
|
38
42
|
seed_: _TState = cast(_TState, seed)
|
|
39
43
|
scanner = ops.scan(accumulator, seed=seed_)
|
|
40
|
-
return
|
|
44
|
+
return source.pipe(
|
|
41
45
|
scanner,
|
|
42
46
|
ops.last_or_default(default_value=seed_),
|
|
43
47
|
)
|
|
44
48
|
|
|
45
|
-
return
|
|
49
|
+
return source.pipe(
|
|
46
50
|
ops.scan(cast(Accumulator[_T, _T], accumulator)),
|
|
47
51
|
ops.last(),
|
|
48
52
|
)
|