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.
Files changed (219) hide show
  1. reactivex/__init__.py +35 -39
  2. reactivex/_version.py +1 -1
  3. reactivex/abc/disposable.py +3 -4
  4. reactivex/abc/observable.py +13 -6
  5. reactivex/abc/observer.py +2 -1
  6. reactivex/abc/periodicscheduler.py +7 -6
  7. reactivex/abc/scheduler.py +10 -9
  8. reactivex/abc/subject.py +5 -5
  9. reactivex/disposable/compositedisposable.py +4 -4
  10. reactivex/disposable/disposable.py +1 -2
  11. reactivex/disposable/multipleassignmentdisposable.py +2 -3
  12. reactivex/disposable/refcountdisposable.py +1 -2
  13. reactivex/disposable/serialdisposable.py +4 -5
  14. reactivex/disposable/singleassignmentdisposable.py +3 -4
  15. reactivex/internal/__init__.py +2 -0
  16. reactivex/internal/basic.py +2 -2
  17. reactivex/internal/concurrency.py +2 -1
  18. reactivex/internal/curry.py +59 -0
  19. reactivex/internal/exceptions.py +7 -12
  20. reactivex/internal/priorityqueue.py +2 -2
  21. reactivex/internal/utils.py +3 -2
  22. reactivex/notification.py +22 -21
  23. reactivex/observable/case.py +5 -6
  24. reactivex/observable/catch.py +3 -2
  25. reactivex/observable/combinelatest.py +4 -5
  26. reactivex/observable/concat.py +3 -2
  27. reactivex/observable/connectableobservable.py +7 -7
  28. reactivex/observable/defer.py +4 -3
  29. reactivex/observable/empty.py +3 -4
  30. reactivex/observable/forkjoin.py +5 -5
  31. reactivex/observable/fromcallback.py +4 -3
  32. reactivex/observable/fromfuture.py +2 -2
  33. reactivex/observable/fromiterable.py +4 -3
  34. reactivex/observable/generate.py +2 -2
  35. reactivex/observable/generatewithrelativetime.py +4 -3
  36. reactivex/observable/groupedobservable.py +4 -4
  37. reactivex/observable/ifthen.py +3 -2
  38. reactivex/observable/interval.py +1 -4
  39. reactivex/observable/marbles.py +18 -17
  40. reactivex/observable/mixins/__init__.py +32 -0
  41. reactivex/observable/mixins/combination.py +481 -0
  42. reactivex/observable/mixins/conditional.py +135 -0
  43. reactivex/observable/mixins/error_handling.py +130 -0
  44. reactivex/observable/mixins/filtering.py +1119 -0
  45. reactivex/observable/mixins/mathematical.py +277 -0
  46. reactivex/observable/mixins/multicasting.py +306 -0
  47. reactivex/observable/mixins/testing.py +193 -0
  48. reactivex/observable/mixins/time_based.py +209 -0
  49. reactivex/observable/mixins/transformation.py +632 -0
  50. reactivex/observable/mixins/utility.py +811 -0
  51. reactivex/observable/mixins/windowing.py +688 -0
  52. reactivex/observable/never.py +2 -2
  53. reactivex/observable/observable.py +72 -25
  54. reactivex/observable/onerrorresumenext.py +7 -6
  55. reactivex/observable/range.py +6 -6
  56. reactivex/observable/repeat.py +2 -2
  57. reactivex/observable/returnvalue.py +6 -5
  58. reactivex/observable/start.py +3 -2
  59. reactivex/observable/startasync.py +2 -1
  60. reactivex/observable/throw.py +3 -3
  61. reactivex/observable/timer.py +12 -12
  62. reactivex/observable/toasync.py +3 -2
  63. reactivex/observable/using.py +5 -4
  64. reactivex/observable/withlatestfrom.py +4 -5
  65. reactivex/observable/zip.py +7 -6
  66. reactivex/observer/autodetachobserver.py +4 -4
  67. reactivex/observer/observer.py +5 -4
  68. reactivex/observer/scheduledobserver.py +2 -2
  69. reactivex/operators/__init__.py +162 -208
  70. reactivex/operators/_all.py +23 -6
  71. reactivex/operators/_amb.py +88 -75
  72. reactivex/operators/_asobservable.py +20 -17
  73. reactivex/operators/_average.py +48 -45
  74. reactivex/operators/_buffer.py +81 -35
  75. reactivex/operators/_bufferwithtime.py +29 -9
  76. reactivex/operators/_bufferwithtimeorcount.py +27 -8
  77. reactivex/operators/_catch.py +33 -32
  78. reactivex/operators/_combinelatest.py +28 -20
  79. reactivex/operators/_concat.py +16 -13
  80. reactivex/operators/_contains.py +25 -6
  81. reactivex/operators/_count.py +24 -8
  82. reactivex/operators/_debounce.py +141 -138
  83. reactivex/operators/_defaultifempty.py +45 -42
  84. reactivex/operators/_delay.py +24 -23
  85. reactivex/operators/_delaysubscription.py +23 -21
  86. reactivex/operators/_delaywithmapper.py +10 -11
  87. reactivex/operators/_dematerialize.py +25 -21
  88. reactivex/operators/_distinct.py +50 -46
  89. reactivex/operators/_distinctuntilchanged.py +60 -57
  90. reactivex/operators/_do.py +123 -116
  91. reactivex/operators/_dowhile.py +3 -2
  92. reactivex/operators/_elementatordefault.py +57 -33
  93. reactivex/operators/_exclusive.py +59 -53
  94. reactivex/operators/_expand.py +82 -77
  95. reactivex/operators/_filter.py +63 -68
  96. reactivex/operators/_finallyaction.py +3 -2
  97. reactivex/operators/_find.py +49 -32
  98. reactivex/operators/_first.py +18 -11
  99. reactivex/operators/_firstordefault.py +5 -4
  100. reactivex/operators/_flatmap.py +89 -83
  101. reactivex/operators/_forkjoin.py +23 -18
  102. reactivex/operators/_groupby.py +27 -6
  103. reactivex/operators/_groupbyuntil.py +8 -5
  104. reactivex/operators/_groupjoin.py +7 -6
  105. reactivex/operators/_ignoreelements.py +20 -15
  106. reactivex/operators/_isempty.py +15 -4
  107. reactivex/operators/_join.py +6 -5
  108. reactivex/operators/_last.py +36 -31
  109. reactivex/operators/_lastordefault.py +8 -8
  110. reactivex/operators/_map.py +54 -39
  111. reactivex/operators/_materialize.py +30 -31
  112. reactivex/operators/_max.py +18 -11
  113. reactivex/operators/_maxby.py +5 -5
  114. reactivex/operators/_merge.py +132 -129
  115. reactivex/operators/_min.py +16 -10
  116. reactivex/operators/_minby.py +9 -8
  117. reactivex/operators/_multicast.py +9 -9
  118. reactivex/operators/_observeon.py +35 -31
  119. reactivex/operators/_onerrorresumenext.py +2 -1
  120. reactivex/operators/_pairwise.py +38 -34
  121. reactivex/operators/_partition.py +80 -73
  122. reactivex/operators/_pluck.py +4 -3
  123. reactivex/operators/_publish.py +36 -21
  124. reactivex/operators/_publishvalue.py +8 -7
  125. reactivex/operators/_reduce.py +16 -12
  126. reactivex/operators/_repeat.py +33 -30
  127. reactivex/operators/_replay.py +9 -9
  128. reactivex/operators/_retry.py +12 -10
  129. reactivex/operators/_sample.py +31 -27
  130. reactivex/operators/_scan.py +41 -39
  131. reactivex/operators/_sequenceequal.py +8 -7
  132. reactivex/operators/_single.py +20 -13
  133. reactivex/operators/_singleordefault.py +6 -5
  134. reactivex/operators/_skip.py +35 -32
  135. reactivex/operators/_skiplast.py +38 -34
  136. reactivex/operators/_skiplastwithtime.py +5 -4
  137. reactivex/operators/_skipuntil.py +40 -35
  138. reactivex/operators/_skipuntilwithtime.py +4 -3
  139. reactivex/operators/_skipwhile.py +65 -44
  140. reactivex/operators/_skipwithtime.py +50 -46
  141. reactivex/operators/_slice.py +58 -53
  142. reactivex/operators/_some.py +48 -47
  143. reactivex/operators/_startswith.py +17 -15
  144. reactivex/operators/_subscribeon.py +44 -41
  145. reactivex/operators/_sum.py +23 -6
  146. reactivex/operators/_switchlatest.py +71 -69
  147. reactivex/operators/_take.py +37 -33
  148. reactivex/operators/_takelast.py +37 -36
  149. reactivex/operators/_takelastbuffer.py +38 -37
  150. reactivex/operators/_takelastwithtime.py +60 -56
  151. reactivex/operators/_takeuntil.py +33 -32
  152. reactivex/operators/_takeuntilwithtime.py +42 -39
  153. reactivex/operators/_takewhile.py +108 -100
  154. reactivex/operators/_takewithtime.py +46 -41
  155. reactivex/operators/_throttlefirst.py +52 -45
  156. reactivex/operators/_timeinterval.py +40 -36
  157. reactivex/operators/_timeout.py +81 -79
  158. reactivex/operators/_timeoutwithmapper.py +6 -5
  159. reactivex/operators/_timestamp.py +24 -22
  160. reactivex/operators/_todict.py +51 -43
  161. reactivex/operators/_tofuture.py +24 -15
  162. reactivex/operators/_toiterable.py +33 -27
  163. reactivex/operators/_tomarbles.py +5 -5
  164. reactivex/operators/_toset.py +29 -19
  165. reactivex/operators/_whiledo.py +2 -1
  166. reactivex/operators/_window.py +100 -99
  167. reactivex/operators/_windowwithcount.py +56 -54
  168. reactivex/operators/_windowwithtime.py +95 -79
  169. reactivex/operators/_windowwithtimeorcount.py +85 -69
  170. reactivex/operators/_withlatestfrom.py +13 -9
  171. reactivex/operators/_zip.py +67 -63
  172. reactivex/operators/connectable/_refcount.py +4 -3
  173. reactivex/pipe.py +2 -1
  174. reactivex/run.py +8 -4
  175. reactivex/scheduler/catchscheduler.py +11 -10
  176. reactivex/scheduler/currentthreadscheduler.py +2 -3
  177. reactivex/scheduler/eventloop/asyncioscheduler.py +7 -6
  178. reactivex/scheduler/eventloop/asynciothreadsafescheduler.py +12 -14
  179. reactivex/scheduler/eventloop/eventletscheduler.py +4 -4
  180. reactivex/scheduler/eventloop/geventscheduler.py +4 -4
  181. reactivex/scheduler/eventloop/ioloopscheduler.py +4 -4
  182. reactivex/scheduler/eventloop/twistedscheduler.py +4 -4
  183. reactivex/scheduler/eventloopscheduler.py +9 -12
  184. reactivex/scheduler/historicalscheduler.py +1 -2
  185. reactivex/scheduler/immediatescheduler.py +5 -4
  186. reactivex/scheduler/mainloop/gtkscheduler.py +6 -7
  187. reactivex/scheduler/mainloop/pygamescheduler.py +4 -4
  188. reactivex/scheduler/mainloop/qtscheduler.py +6 -6
  189. reactivex/scheduler/mainloop/tkinterscheduler.py +4 -4
  190. reactivex/scheduler/mainloop/wxscheduler.py +7 -7
  191. reactivex/scheduler/newthreadscheduler.py +6 -8
  192. reactivex/scheduler/periodicscheduler.py +4 -4
  193. reactivex/scheduler/scheduleditem.py +4 -4
  194. reactivex/scheduler/scheduler.py +5 -5
  195. reactivex/scheduler/threadpoolscheduler.py +3 -3
  196. reactivex/scheduler/timeoutscheduler.py +5 -4
  197. reactivex/scheduler/trampoline.py +1 -2
  198. reactivex/scheduler/trampolinescheduler.py +5 -6
  199. reactivex/scheduler/virtualtimescheduler.py +4 -4
  200. reactivex/subject/asyncsubject.py +2 -2
  201. reactivex/subject/behaviorsubject.py +2 -2
  202. reactivex/subject/innersubscription.py +2 -2
  203. reactivex/subject/replaysubject.py +8 -8
  204. reactivex/subject/subject.py +4 -4
  205. reactivex/testing/coldobservable.py +5 -5
  206. reactivex/testing/hotobservable.py +6 -6
  207. reactivex/testing/marbles.py +21 -20
  208. reactivex/testing/mockdisposable.py +1 -3
  209. reactivex/testing/mockobserver.py +2 -2
  210. reactivex/testing/reactivetest.py +2 -2
  211. reactivex/testing/recorded.py +1 -1
  212. reactivex/testing/subscription.py +3 -3
  213. reactivex/testing/testscheduler.py +13 -12
  214. reactivex/typing.py +25 -14
  215. {reactivex-4.1.0.dist-info → reactivex-5.0.0a2.dist-info}/METADATA +59 -26
  216. reactivex-5.0.0a2.dist-info/RECORD +236 -0
  217. {reactivex-4.1.0.dist-info → reactivex-5.0.0a2.dist-info}/WHEEL +1 -1
  218. reactivex-4.1.0.dist-info/RECORD +0 -223
  219. {reactivex-4.1.0.dist-info → reactivex-5.0.0a2.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,193 @@
1
+ """Testing operators mixin for Observable."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import Iterable
6
+ from typing import TYPE_CHECKING, Any, Generic, TypeVar, cast
7
+
8
+ from reactivex import typing
9
+
10
+ if TYPE_CHECKING:
11
+ from reactivex.observable import Observable
12
+
13
+ _T = TypeVar("_T", covariant=True)
14
+
15
+
16
+ class TestingMixin(Generic[_T]):
17
+ """Mixin providing testing operators for Observable.
18
+
19
+ This mixin adds operators that test properties of observable sequences,
20
+ including checking conditions, emptiness, and equality.
21
+ """
22
+
23
+ def _as_observable(self) -> Observable[_T]:
24
+ """Cast mixin instance to Observable preserving type parameter.
25
+
26
+ This is safe because this mixin is only ever used as part of the Observable
27
+ class through multiple inheritance. At runtime, `self` in mixin methods will
28
+ always be an Observable[_T] instance. The type checker cannot infer this
29
+ because it analyzes mixins in isolation.
30
+
31
+ Returns:
32
+ The instance cast to Observable[_T] for type-safe method access.
33
+ """
34
+ return cast("Observable[_T]", self)
35
+
36
+ def all(self, predicate: typing.Predicate[_T]) -> Observable[bool]:
37
+ """Check if all elements satisfy a condition.
38
+
39
+ Determines whether all elements of an observable sequence satisfy
40
+ a condition.
41
+
42
+ Examples:
43
+ Fluent style:
44
+ >>> result = source.all(lambda x: x > 0)
45
+
46
+ Equivalent pipe style:
47
+ >>> from reactivex import operators as ops
48
+ >>> result = source.pipe(ops.all(lambda x: x > 0))
49
+
50
+ Args:
51
+ predicate: A function to test each element for a condition.
52
+
53
+ Returns:
54
+ An observable sequence containing a single boolean value
55
+ indicating whether all elements in the source sequence pass
56
+ the test in the specified predicate.
57
+
58
+ See Also:
59
+ - :func:`all <reactivex.operators.all>`
60
+ - :meth:`some`
61
+ """
62
+ from reactivex import operators as ops
63
+
64
+ return self._as_observable().pipe(ops.all(predicate))
65
+
66
+ def some(self, predicate: typing.Predicate[_T] | None = None) -> Observable[bool]:
67
+ """Check if some elements satisfy a condition.
68
+
69
+ Determines whether some element of an observable sequence satisfies
70
+ a condition if present, else if some items are in the sequence.
71
+
72
+ Examples:
73
+ Fluent style:
74
+ >>> result = source.some(lambda x: x > 10)
75
+ >>> result = source.some() # Check if sequence is not empty
76
+
77
+ Equivalent pipe style:
78
+ >>> from reactivex import operators as ops
79
+ >>> result = source.pipe(ops.some(lambda x: x > 10))
80
+
81
+ Args:
82
+ predicate: A function to test each element for a condition.
83
+ If not specified, checks if the sequence contains any elements.
84
+
85
+ Returns:
86
+ An observable sequence containing a single boolean value
87
+ indicating whether at least one element in the source sequence
88
+ passes the test (or whether the sequence is non-empty if no
89
+ predicate is specified).
90
+
91
+ See Also:
92
+ - :func:`some <reactivex.operators.some>`
93
+ - :meth:`all`
94
+ - :meth:`is_empty`
95
+ """
96
+ from reactivex import operators as ops
97
+
98
+ return self._as_observable().pipe(ops.some(predicate))
99
+
100
+ def is_empty(self) -> Observable[bool]:
101
+ """Check if the sequence is empty.
102
+
103
+ Determines whether an observable sequence is empty.
104
+
105
+ Examples:
106
+ Fluent style:
107
+ >>> result = source.is_empty()
108
+
109
+ Equivalent pipe style:
110
+ >>> from reactivex import operators as ops
111
+ >>> result = source.pipe(ops.is_empty())
112
+
113
+ Returns:
114
+ An observable sequence containing a single boolean value
115
+ indicating whether the source sequence is empty.
116
+
117
+ See Also:
118
+ - :func:`is_empty <reactivex.operators.is_empty>`
119
+ - :meth:`some`
120
+ """
121
+ from reactivex import operators as ops
122
+
123
+ return self._as_observable().pipe(ops.is_empty())
124
+
125
+ def contains(
126
+ self, value: Any, comparer: typing.Comparer[Any] | None = None
127
+ ) -> Observable[bool]:
128
+ """Check if the sequence contains a value.
129
+
130
+ Determines whether an observable sequence contains a specified
131
+ element with an optional equality comparer.
132
+
133
+ Examples:
134
+ Fluent style:
135
+ >>> result = source.contains(42)
136
+ >>> result = source.contains("hello", lambda a, b: a.lower() == b.lower())
137
+
138
+ Equivalent pipe style:
139
+ >>> from reactivex import operators as ops
140
+ >>> result = source.pipe(ops.contains(42))
141
+
142
+ Args:
143
+ value: The value to locate in the source sequence.
144
+ comparer: An equality comparer to compare elements.
145
+
146
+ Returns:
147
+ An observable sequence containing a single boolean value
148
+ indicating whether the source sequence contains an element
149
+ that has the specified value.
150
+
151
+ See Also:
152
+ - :func:`contains <reactivex.operators.contains>`
153
+ - :meth:`some`
154
+ """
155
+ from reactivex import operators as ops
156
+
157
+ return self._as_observable().pipe(ops.contains(value, comparer))
158
+
159
+ def sequence_equal(
160
+ self,
161
+ second: Observable[_T] | Iterable[_T],
162
+ comparer: typing.Comparer[_T] | None = None,
163
+ ) -> Observable[bool]:
164
+ """Check if two sequences are equal.
165
+
166
+ Determines whether two sequences are equal by comparing the
167
+ elements pairwise using a specified equality comparer.
168
+
169
+ Examples:
170
+ Fluent style:
171
+ >>> result = source.sequence_equal(other_observable)
172
+ >>> result = source.sequence_equal([1, 2, 3])
173
+
174
+ Equivalent pipe style:
175
+ >>> from reactivex import operators as ops
176
+ >>> result = source.pipe(ops.sequence_equal(other_observable))
177
+
178
+ Args:
179
+ second: Second observable sequence or iterable to compare.
180
+ comparer: Comparer used to compare elements of both sequences.
181
+
182
+ Returns:
183
+ An observable sequence that contains a single boolean value
184
+ which indicates whether both sequences are of equal length and
185
+ their corresponding elements are equal according to the
186
+ specified comparer.
187
+
188
+ See Also:
189
+ - :func:`sequence_equal <reactivex.operators.sequence_equal>`
190
+ """
191
+ from reactivex import operators as ops
192
+
193
+ return self._as_observable().pipe(ops.sequence_equal(second, comparer))
@@ -0,0 +1,209 @@
1
+ """Time-based operators mixin for Observable."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import TYPE_CHECKING, Any, Generic, TypeVar, cast
6
+
7
+ from reactivex import abc, typing
8
+
9
+ if TYPE_CHECKING:
10
+ from reactivex.observable import Observable
11
+
12
+
13
+ _T = TypeVar("_T", covariant=True)
14
+
15
+
16
+ class TimeBasedMixin(Generic[_T]):
17
+ """Mixin providing time-based operators for Observable.
18
+
19
+ This mixin adds operators that work with time, including sampling and debouncing.
20
+ """
21
+
22
+ def _as_observable(self) -> Observable[_T]:
23
+ """Cast mixin instance to Observable preserving type parameter.
24
+
25
+ This is safe because this mixin is only ever used as part of the Observable
26
+ class through multiple inheritance. At runtime, `self` in mixin methods will
27
+ always be an Observable[_T] instance. The type checker cannot infer this
28
+ because it analyzes mixins in isolation.
29
+
30
+ Returns:
31
+ The instance cast to Observable[_T] for type-safe method access.
32
+ """
33
+ return cast("Observable[_T]", self)
34
+
35
+ def sample(
36
+ self,
37
+ sampler: typing.RelativeTime | Observable[Any],
38
+ scheduler: abc.SchedulerBase | None = None,
39
+ ) -> Observable[_T]:
40
+ """Sample the sequence at intervals.
41
+
42
+ Samples the observable sequence at each interval.
43
+
44
+ Examples:
45
+ Fluent style:
46
+ >>> result = source.sample(1.0)
47
+ >>> result = source.sample(trigger_observable)
48
+
49
+ Equivalent pipe style:
50
+ >>> from reactivex import operators as ops
51
+ >>> result = source.pipe(ops.sample(1.0))
52
+
53
+ Args:
54
+ sampler: Interval or observable that triggers sampling.
55
+ scheduler: Scheduler to use for timing intervals.
56
+
57
+ Returns:
58
+ Sampled observable sequence.
59
+
60
+ See Also:
61
+ - :func:`sample <reactivex.operators.sample>`
62
+ - :meth:`throttle_first`
63
+ - :meth:`debounce`
64
+ """
65
+ from reactivex import operators as ops
66
+
67
+ return self._as_observable().pipe(ops.sample(sampler, scheduler))
68
+
69
+ def debounce(
70
+ self,
71
+ duetime: typing.RelativeTime,
72
+ scheduler: abc.SchedulerBase | None = None,
73
+ ) -> Observable[_T]:
74
+ """Debounce the sequence.
75
+
76
+ Ignores values from an observable sequence which are followed by another
77
+ value before duetime.
78
+
79
+ Examples:
80
+ Fluent style:
81
+ >>> result = source.debounce(0.5)
82
+
83
+ Equivalent pipe style:
84
+ >>> from reactivex import operators as ops
85
+ >>> result = source.pipe(ops.debounce(0.5))
86
+
87
+ Args:
88
+ duetime: Duration of the debounce period for each value.
89
+ scheduler: Scheduler to use for timing debounce.
90
+
91
+ Returns:
92
+ The debounced sequence.
93
+
94
+ See Also:
95
+ - :func:`debounce <reactivex.operators.debounce>`
96
+ - :meth:`throttle_first`
97
+ - :meth:`sample`
98
+ """
99
+ from reactivex import operators as ops
100
+
101
+ return self._as_observable().pipe(ops.debounce(duetime, scheduler))
102
+
103
+ def throttle_first(
104
+ self,
105
+ window_duration: typing.RelativeTime,
106
+ scheduler: abc.SchedulerBase | None = None,
107
+ ) -> Observable[_T]:
108
+ """Emit only first item in each time window.
109
+
110
+ Returns an Observable that emits only the first item emitted by
111
+ the source Observable during sequential time windows of a specified
112
+ duration.
113
+
114
+ Examples:
115
+ Fluent style:
116
+ >>> result = source.throttle_first(1.0)
117
+
118
+ Equivalent pipe style:
119
+ >>> from reactivex import operators as ops
120
+ >>> result = source.pipe(ops.throttle_first(1.0))
121
+
122
+ Args:
123
+ window_duration: Time to wait before emitting another value.
124
+ scheduler: Scheduler to use for timing windows.
125
+
126
+ Returns:
127
+ An observable sequence that emits only the first item in each window.
128
+
129
+ See Also:
130
+ - :func:`throttle_first <reactivex.operators.throttle_first>`
131
+ - :meth:`debounce`
132
+ - :meth:`sample`
133
+ """
134
+ from reactivex import operators as ops
135
+
136
+ return self._as_observable().pipe(
137
+ ops.throttle_first(window_duration, scheduler)
138
+ )
139
+
140
+ def throttle_with_mapper(
141
+ self,
142
+ throttle_duration_mapper: typing.Callable[[Any], Observable[Any]],
143
+ ) -> Observable[_T]:
144
+ """Throttle with custom duration selector.
145
+
146
+ Ignores values from an observable sequence which are followed by
147
+ another value within a computed throttle duration.
148
+
149
+ Examples:
150
+ Fluent style:
151
+ >>> result = source.throttle_with_mapper(lambda x: rx.timer(x * 0.1))
152
+
153
+ Equivalent pipe style:
154
+ >>> from reactivex import operators as ops
155
+ >>> result = source.pipe(
156
+ ... ops.throttle_with_mapper(lambda x: rx.timer(x * 0.1))
157
+ ... )
158
+
159
+ Args:
160
+ throttle_duration_mapper: Function to compute throttle duration
161
+ for each item.
162
+
163
+ Returns:
164
+ The throttled sequence.
165
+
166
+ See Also:
167
+ - :func:`throttle_with_mapper <reactivex.operators.throttle_with_mapper>`
168
+ - :meth:`debounce`
169
+ - :meth:`throttle_first`
170
+ """
171
+ from reactivex import operators as ops
172
+
173
+ return self._as_observable().pipe(
174
+ ops.throttle_with_mapper(throttle_duration_mapper)
175
+ )
176
+
177
+ def throttle_with_timeout(
178
+ self,
179
+ duetime: typing.RelativeTime,
180
+ scheduler: abc.SchedulerBase | None = None,
181
+ ) -> Observable[_T]:
182
+ """Throttle with timeout (alias for debounce).
183
+
184
+ Ignores values from an observable sequence which are followed by another
185
+ value before duetime. This is an alias for debounce.
186
+
187
+ Examples:
188
+ Fluent style:
189
+ >>> result = source.throttle_with_timeout(0.5)
190
+
191
+ Equivalent pipe style:
192
+ >>> from reactivex import operators as ops
193
+ >>> result = source.pipe(ops.throttle_with_timeout(0.5))
194
+
195
+ Args:
196
+ duetime: Duration of the throttle period for each value.
197
+ scheduler: Scheduler to use for timing throttle.
198
+
199
+ Returns:
200
+ The throttled sequence.
201
+
202
+ See Also:
203
+ - :func:`throttle_with_timeout <reactivex.operators.throttle_with_timeout>`
204
+ - :meth:`debounce`
205
+ - :meth:`throttle_first`
206
+ """
207
+ from reactivex import operators as ops
208
+
209
+ return self._as_observable().pipe(ops.throttle_with_timeout(duetime, scheduler))