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,811 @@
1
+ """Utility 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 UtilityMixin(Generic[_T]):
17
+ """Mixin providing utility operators for Observable.
18
+
19
+ This mixin adds operators that provide utility functionality,
20
+ including side effects, timing, scheduling, and notification handling.
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 do_action(
37
+ self,
38
+ on_next: typing.OnNext[_T] | None = None,
39
+ on_error: typing.OnError | None = None,
40
+ on_completed: typing.OnCompleted | None = None,
41
+ ) -> Observable[_T]:
42
+ """Invoke side effects for each element.
43
+
44
+ Invokes an action for each element in the observable sequence and invokes
45
+ an action on graceful or exceptional termination.
46
+
47
+ Examples:
48
+ Fluent style:
49
+ >>> result = source.do_action(print)
50
+ >>> result = source.do_action(
51
+ ... on_next=lambda x: print(f"Value: {x}"),
52
+ ... on_error=lambda e: print(f"Error: {e}"),
53
+ ... on_completed=lambda: print("Done")
54
+ ... )
55
+
56
+ Equivalent pipe style:
57
+ >>> from reactivex import operators as ops
58
+ >>> result = source.pipe(ops.do_action(print))
59
+
60
+ Args:
61
+ on_next: Action to invoke for each element.
62
+ on_error: Action to invoke upon exceptional termination.
63
+ on_completed: Action to invoke upon graceful termination.
64
+
65
+ Returns:
66
+ The source sequence with the side-effecting behavior applied.
67
+
68
+ See Also:
69
+ - :func:`do_action <reactivex.operators.do_action>`
70
+ """
71
+ from reactivex import operators as ops
72
+
73
+ return self._as_observable().pipe(
74
+ ops.do_action(on_next, on_error, on_completed)
75
+ )
76
+
77
+ def delay(
78
+ self, duetime: typing.RelativeTime, scheduler: abc.SchedulerBase | None = None
79
+ ) -> Observable[_T]:
80
+ """Delay emissions by a specified time.
81
+
82
+ Time shifts the observable sequence by the specified relative time.
83
+
84
+ Examples:
85
+ Fluent style:
86
+ >>> result = source.delay(1.0)
87
+ >>> result = source.delay(timedelta(seconds=5))
88
+
89
+ Equivalent pipe style:
90
+ >>> from reactivex import operators as ops
91
+ >>> result = source.pipe(ops.delay(1.0))
92
+
93
+ Args:
94
+ duetime: Relative time by which to shift the observable sequence.
95
+ scheduler: Scheduler to run the delay timers on.
96
+
97
+ Returns:
98
+ Time-shifted sequence.
99
+
100
+ See Also:
101
+ - :func:`delay <reactivex.operators.delay>`
102
+ - :meth:`delay_subscription`
103
+ """
104
+ from reactivex import operators as ops
105
+
106
+ return self._as_observable().pipe(ops.delay(duetime, scheduler))
107
+
108
+ def timeout(
109
+ self,
110
+ duetime: typing.AbsoluteOrRelativeTime,
111
+ other: Observable[_T] | None = None,
112
+ scheduler: abc.SchedulerBase | None = None,
113
+ ) -> Observable[_T]:
114
+ """Apply a timeout to the sequence.
115
+
116
+ Returns the source observable sequence or the other observable sequence
117
+ if the maximum duration between values elapses.
118
+
119
+ Examples:
120
+ Fluent style:
121
+ >>> result = source.timeout(1.0)
122
+ >>> result = source.timeout(5.0, fallback_observable)
123
+
124
+ Equivalent pipe style:
125
+ >>> from reactivex import operators as ops
126
+ >>> result = source.pipe(ops.timeout(1.0))
127
+
128
+ Args:
129
+ duetime: Maximum duration between values before a timeout occurs.
130
+ other: Sequence to return in case of a timeout.
131
+ scheduler: Scheduler to run the timeout timers on.
132
+
133
+ Returns:
134
+ The source sequence switching to the other sequence in case of a timeout.
135
+
136
+ See Also:
137
+ - :func:`timeout <reactivex.operators.timeout>`
138
+ """
139
+ from reactivex import operators as ops
140
+
141
+ return self._as_observable().pipe(ops.timeout(duetime, other, scheduler))
142
+
143
+ def timestamp(self, scheduler: abc.SchedulerBase | None = None) -> Observable[Any]:
144
+ """Add timestamps to elements.
145
+
146
+ Records the timestamp for each value in an observable sequence.
147
+
148
+ Examples:
149
+ Fluent style:
150
+ >>> result = source.timestamp()
151
+
152
+ Equivalent pipe style:
153
+ >>> from reactivex import operators as ops
154
+ >>> result = source.pipe(ops.timestamp())
155
+
156
+ Args:
157
+ scheduler: Scheduler to use for timestamping.
158
+
159
+ Returns:
160
+ An observable sequence with timestamp information on elements.
161
+
162
+ See Also:
163
+ - :func:`timestamp <reactivex.operators.timestamp>`
164
+ - :meth:`time_interval`
165
+ """
166
+ from reactivex import operators as ops
167
+
168
+ return self._as_observable().pipe(ops.timestamp(scheduler))
169
+
170
+ def observe_on(self, scheduler: abc.SchedulerBase) -> Observable[_T]:
171
+ """Observe on a specific scheduler.
172
+
173
+ Wraps the source sequence in order to run its observer callbacks on the
174
+ specified scheduler.
175
+
176
+ Examples:
177
+ Fluent style:
178
+ >>> result = source.observe_on(scheduler)
179
+
180
+ Equivalent pipe style:
181
+ >>> from reactivex import operators as ops
182
+ >>> result = source.pipe(ops.observe_on(scheduler))
183
+
184
+ Args:
185
+ scheduler: Scheduler to notify observers on.
186
+
187
+ Returns:
188
+ The source sequence whose observations happen on the specified scheduler.
189
+
190
+ See Also:
191
+ - :func:`observe_on <reactivex.operators.observe_on>`
192
+ - :meth:`subscribe_on`
193
+ """
194
+ from reactivex import operators as ops
195
+
196
+ return self._as_observable().pipe(ops.observe_on(scheduler))
197
+
198
+ def subscribe_on(self, scheduler: abc.SchedulerBase) -> Observable[_T]:
199
+ """Subscribe on a specific scheduler.
200
+
201
+ Wrap the source sequence in order to run its subscription and unsubscription
202
+ logic on the specified scheduler.
203
+
204
+ Examples:
205
+ Fluent style:
206
+ >>> result = source.subscribe_on(scheduler)
207
+
208
+ Equivalent pipe style:
209
+ >>> from reactivex import operators as ops
210
+ >>> result = source.pipe(ops.subscribe_on(scheduler))
211
+
212
+ Args:
213
+ scheduler: Scheduler to perform subscription and unsubscription actions on.
214
+
215
+ Returns:
216
+ The source sequence whose subscriptions and unsubscriptions happen on
217
+ the specified scheduler.
218
+
219
+ See Also:
220
+ - :func:`subscribe_on <reactivex.operators.subscribe_on>`
221
+ - :meth:`observe_on`
222
+ """
223
+ from reactivex import operators as ops
224
+
225
+ return self._as_observable().pipe(ops.subscribe_on(scheduler))
226
+
227
+ def materialize(self) -> Observable[Any]:
228
+ """Materialize notifications as explicit values.
229
+
230
+ Materializes the implicit notifications of an observable
231
+ sequence as explicit notification values.
232
+
233
+ Examples:
234
+ Fluent style:
235
+ >>> result = source.materialize()
236
+
237
+ Equivalent pipe style:
238
+ >>> from reactivex import operators as ops
239
+ >>> result = source.pipe(ops.materialize())
240
+
241
+ Returns:
242
+ An observable sequence containing the materialized
243
+ notification values from the source sequence.
244
+
245
+ See Also:
246
+ - :func:`materialize <reactivex.operators.materialize>`
247
+ - :meth:`dematerialize`
248
+ """
249
+ from reactivex import operators as ops
250
+
251
+ return self._as_observable().pipe(ops.materialize())
252
+
253
+ def dematerialize(self) -> Observable[Any]:
254
+ """Dematerialize explicit notifications.
255
+
256
+ Dematerializes the explicit notification values of an
257
+ observable sequence as implicit notifications.
258
+
259
+ Examples:
260
+ Fluent style:
261
+ >>> result = source.dematerialize()
262
+
263
+ Equivalent pipe style:
264
+ >>> from reactivex import operators as ops
265
+ >>> result = source.pipe(ops.dematerialize())
266
+
267
+ Returns:
268
+ An observable sequence exhibiting the behavior
269
+ corresponding to the source sequence's notification values.
270
+
271
+ See Also:
272
+ - :func:`dematerialize <reactivex.operators.dematerialize>`
273
+ - :meth:`materialize`
274
+ """
275
+ from reactivex import operators as ops
276
+
277
+ # Cast is safe: dematerialize is meant to be called on
278
+ # Observable[Notification[T]]. The fluent API allows chaining
279
+ # this on materialized sequences. The cast preserves type
280
+ # safety for the intended use case where _T is Notification[T].
281
+ from reactivex.notification import Notification
282
+
283
+ source: Observable[Notification[Any]] = cast(
284
+ "Observable[Notification[Any]]", self._as_observable()
285
+ )
286
+ return ops.dematerialize()(source)
287
+
288
+ def time_interval(
289
+ self, scheduler: abc.SchedulerBase | None = None
290
+ ) -> Observable[Any]:
291
+ """Record time intervals between values.
292
+
293
+ Records the time interval between consecutive values in an
294
+ observable sequence.
295
+
296
+ Examples:
297
+ Fluent style:
298
+ >>> result = source.time_interval()
299
+
300
+ Equivalent pipe style:
301
+ >>> from reactivex import operators as ops
302
+ >>> result = source.pipe(ops.time_interval())
303
+
304
+ Args:
305
+ scheduler: Scheduler to use for measuring time intervals.
306
+
307
+ Returns:
308
+ An observable sequence with time interval information on values.
309
+
310
+ See Also:
311
+ - :func:`time_interval <reactivex.operators.time_interval>`
312
+ - :meth:`timestamp`
313
+ """
314
+ from reactivex import operators as ops
315
+
316
+ return self._as_observable().pipe(ops.time_interval(scheduler))
317
+
318
+ def delay_subscription(
319
+ self,
320
+ duetime: typing.AbsoluteOrRelativeTime,
321
+ scheduler: abc.SchedulerBase | None = None,
322
+ ) -> Observable[_T]:
323
+ """Delay subscription to the source.
324
+
325
+ Time shifts the observable sequence by delaying the
326
+ subscription.
327
+
328
+ Examples:
329
+ Fluent style:
330
+ >>> result = source.delay_subscription(5.0)
331
+
332
+ Equivalent pipe style:
333
+ >>> from reactivex import operators as ops
334
+ >>> result = source.pipe(ops.delay_subscription(5.0))
335
+
336
+ Args:
337
+ duetime: Absolute or relative time to delay subscription.
338
+ scheduler: Scheduler to run the subscription delay timer on.
339
+
340
+ Returns:
341
+ Time-shifted sequence.
342
+
343
+ See Also:
344
+ - :func:`delay_subscription <reactivex.operators.delay_subscription>`
345
+ - :meth:`delay`
346
+ """
347
+ from reactivex import operators as ops
348
+
349
+ return self._as_observable().pipe(ops.delay_subscription(duetime, scheduler))
350
+
351
+ def do(
352
+ self,
353
+ on_next: typing.OnNext[_T] | None = None,
354
+ on_error: typing.OnError | None = None,
355
+ on_completed: typing.OnCompleted | None = None,
356
+ ) -> Observable[_T]:
357
+ """Alias for do_action.
358
+
359
+ Invoke side effects for each element.
360
+
361
+ Examples:
362
+ Fluent style:
363
+ >>> result = source.do(print)
364
+
365
+ Equivalent pipe style:
366
+ >>> from reactivex import operators as ops
367
+ >>> result = source.pipe(ops.do_action(print))
368
+
369
+ Args:
370
+ on_next: Action to invoke for each element.
371
+ on_error: Action to invoke upon exceptional termination.
372
+ on_completed: Action to invoke upon graceful termination.
373
+
374
+ Returns:
375
+ The source sequence with the side-effecting behavior applied.
376
+
377
+ See Also:
378
+ - :meth:`do_action`
379
+ """
380
+ return self.do_action(on_next, on_error, on_completed)
381
+
382
+ def do_while(self, condition: typing.Predicate[Observable[_T]]) -> Observable[_T]:
383
+ """Repeat source as long as condition holds.
384
+
385
+ Repeats source as long as condition holds emulating a do-while loop.
386
+
387
+ Examples:
388
+ Fluent style:
389
+ >>> result = source.do_while(lambda obs: should_continue())
390
+
391
+ Equivalent pipe style:
392
+ >>> from reactivex import operators as ops
393
+ >>> result = source.pipe(ops.do_while(lambda obs: should_continue()))
394
+
395
+ Args:
396
+ condition: The condition which determines if the source will be
397
+ repeated.
398
+
399
+ Returns:
400
+ An observable sequence which is repeated as long as the condition
401
+ holds.
402
+
403
+ See Also:
404
+ - :func:`do_while <reactivex.operators.do_while>`
405
+ - :meth:`while_do`
406
+ - :meth:`repeat`
407
+ """
408
+ from reactivex import operators as ops
409
+
410
+ return self._as_observable().pipe(ops.do_while(condition))
411
+
412
+ def while_do(self, condition: typing.Predicate[Observable[_T]]) -> Observable[_T]:
413
+ """Repeat source as long as condition holds.
414
+
415
+ Repeats source as long as condition holds emulating a while loop.
416
+
417
+ Examples:
418
+ Fluent style:
419
+ >>> result = source.while_do(lambda obs: should_continue())
420
+
421
+ Equivalent pipe style:
422
+ >>> from reactivex import operators as ops
423
+ >>> result = source.pipe(ops.while_do(lambda obs: should_continue()))
424
+
425
+ Args:
426
+ condition: The condition which determines if the source will be
427
+ repeated.
428
+
429
+ Returns:
430
+ An observable sequence which is repeated as long as the condition
431
+ holds.
432
+
433
+ See Also:
434
+ - :func:`while_do <reactivex.operators.while_do>`
435
+ - :meth:`do_while`
436
+ - :meth:`repeat`
437
+ """
438
+ from reactivex import operators as ops
439
+
440
+ return self._as_observable().pipe(ops.while_do(condition))
441
+
442
+ def finally_action(self, action: typing.Action) -> Observable[_T]:
443
+ """Invoke action after termination.
444
+
445
+ Invokes a specified action after the source observable sequence
446
+ terminates gracefully or exceptionally.
447
+
448
+ Examples:
449
+ Fluent style:
450
+ >>> result = source.finally_action(lambda: print("Cleanup"))
451
+
452
+ Equivalent pipe style:
453
+ >>> from reactivex import operators as ops
454
+ >>> result = source.pipe(ops.finally_action(lambda: print("Cleanup")))
455
+
456
+ Args:
457
+ action: Action to invoke after the source terminates.
458
+
459
+ Returns:
460
+ Source sequence with the action-invoking termination behavior
461
+ applied.
462
+
463
+ See Also:
464
+ - :func:`finally_action <reactivex.operators.finally_action>`
465
+ """
466
+ from reactivex import operators as ops
467
+
468
+ return self._as_observable().pipe(ops.finally_action(action))
469
+
470
+ def ignore_elements(self) -> Observable[_T]:
471
+ """Ignore all elements.
472
+
473
+ Ignores all elements in an observable sequence leaving only the
474
+ termination messages.
475
+
476
+ Examples:
477
+ Fluent style:
478
+ >>> result = source.ignore_elements()
479
+
480
+ Equivalent pipe style:
481
+ >>> from reactivex import operators as ops
482
+ >>> result = source.pipe(ops.ignore_elements())
483
+
484
+ Returns:
485
+ An empty observable sequence that signals termination, successful
486
+ or exceptional, of the source sequence.
487
+
488
+ See Also:
489
+ - :func:`ignore_elements <reactivex.operators.ignore_elements>`
490
+ """
491
+ from reactivex import operators as ops
492
+
493
+ return self._as_observable().pipe(ops.ignore_elements())
494
+
495
+ def repeat(self, repeat_count: int | None = None) -> Observable[_T]:
496
+ """Repeat the sequence.
497
+
498
+ Repeats the observable sequence a specified number of times. If the
499
+ repeat count is not specified, the sequence repeats indefinitely.
500
+
501
+ Examples:
502
+ Fluent style:
503
+ >>> result = source.repeat(3)
504
+ >>> result = source.repeat() # infinite
505
+
506
+ Equivalent pipe style:
507
+ >>> from reactivex import operators as ops
508
+ >>> result = source.pipe(ops.repeat(3))
509
+
510
+ Args:
511
+ repeat_count: Number of times to repeat the sequence. If not
512
+ specified, repeats indefinitely.
513
+
514
+ Returns:
515
+ The observable sequence producing the elements of the given
516
+ sequence repeatedly.
517
+
518
+ See Also:
519
+ - :func:`repeat <reactivex.operators.repeat>`
520
+ - :meth:`retry`
521
+ """
522
+ from reactivex import operators as ops
523
+
524
+ return self._as_observable().pipe(ops.repeat(repeat_count))
525
+
526
+ def to_iterable(self) -> Observable[list[_T]]:
527
+ """Convert to iterable.
528
+
529
+ Creates an iterable (list) from an observable sequence.
530
+
531
+ Examples:
532
+ Fluent style:
533
+ >>> result = source.to_iterable()
534
+
535
+ Equivalent pipe style:
536
+ >>> from reactivex import operators as ops
537
+ >>> result = source.pipe(ops.to_iterable())
538
+
539
+ Returns:
540
+ An observable sequence containing a single element which is a list
541
+ containing all the elements of the source sequence.
542
+
543
+ See Also:
544
+ - :func:`to_iterable <reactivex.operators.to_iterable>`
545
+ - :meth:`to_list`
546
+ - :meth:`to_set`
547
+ """
548
+ from reactivex import operators as ops
549
+
550
+ return self._as_observable().pipe(ops.to_iterable())
551
+
552
+ def to_list(self) -> Observable[list[_T]]:
553
+ """Convert to list.
554
+
555
+ Alias for to_iterable. Creates a list from an observable sequence.
556
+
557
+ Examples:
558
+ Fluent style:
559
+ >>> result = source.to_list()
560
+
561
+ Equivalent pipe style:
562
+ >>> from reactivex import operators as ops
563
+ >>> result = source.pipe(ops.to_list())
564
+
565
+ Returns:
566
+ An observable sequence containing a single element which is a list
567
+ containing all the elements of the source sequence.
568
+
569
+ See Also:
570
+ - :func:`to_list <reactivex.operators.to_list>`
571
+ - :meth:`to_iterable`
572
+ """
573
+ return self.to_iterable()
574
+
575
+ def to_set(self) -> Observable[set[_T]]:
576
+ """Convert to set.
577
+
578
+ Converts the observable sequence to a set.
579
+
580
+ Examples:
581
+ Fluent style:
582
+ >>> result = source.to_set()
583
+
584
+ Equivalent pipe style:
585
+ >>> from reactivex import operators as ops
586
+ >>> result = source.pipe(ops.to_set())
587
+
588
+ Returns:
589
+ An observable sequence with a single value of a set containing all
590
+ the elements of the source sequence.
591
+
592
+ See Also:
593
+ - :func:`to_set <reactivex.operators.to_set>`
594
+ - :meth:`to_list`
595
+ """
596
+ from reactivex import operators as ops
597
+
598
+ return self._as_observable().pipe(ops.to_set())
599
+
600
+ def to_dict(
601
+ self,
602
+ key_mapper: typing.Mapper[_T, Any],
603
+ element_mapper: typing.Mapper[_T, Any] | None = None,
604
+ ) -> Observable[dict[Any, Any]]:
605
+ """Convert to dictionary.
606
+
607
+ Converts the observable sequence to a dictionary (Map).
608
+
609
+ Examples:
610
+ Fluent style:
611
+ >>> result = source.to_dict(lambda x: x.id)
612
+ >>> result = source.to_dict(lambda x: x.id, lambda x: x.value)
613
+
614
+ Equivalent pipe style:
615
+ >>> from reactivex import operators as ops
616
+ >>> result = source.pipe(ops.to_dict(lambda x: x.id))
617
+
618
+ Args:
619
+ key_mapper: A function which produces the key for the dictionary.
620
+ element_mapper: An optional function which produces the element for
621
+ the dictionary. If not present, the value will be the element.
622
+
623
+ Returns:
624
+ An observable sequence with a single value of a dictionary
625
+ containing the elements of the source sequence.
626
+
627
+ See Also:
628
+ - :func:`to_dict <reactivex.operators.to_dict>`
629
+ """
630
+ from reactivex import operators as ops
631
+
632
+ return self._as_observable().pipe(ops.to_dict(key_mapper, element_mapper))
633
+
634
+ def to_future(self, future_ctor: Any = None) -> Any:
635
+ """Convert to future.
636
+
637
+ Converts an observable sequence to a Future.
638
+
639
+ Examples:
640
+ Fluent style:
641
+ >>> future = source.to_future()
642
+
643
+ Equivalent pipe style:
644
+ >>> from reactivex import operators as ops
645
+ >>> future = source.pipe(ops.to_future())
646
+
647
+ Args:
648
+ future_ctor: A function which returns a future. If not provided,
649
+ defaults to creating an asyncio.Future.
650
+
651
+ Returns:
652
+ A future with the last value from the observable sequence.
653
+
654
+ See Also:
655
+ - :func:`to_future <reactivex.operators.to_future>`
656
+ """
657
+ from reactivex import operators as ops
658
+
659
+ return self._as_observable().pipe(ops.to_future(future_ctor))
660
+
661
+ def to_marbles(
662
+ self,
663
+ timespan: typing.RelativeTime = 0.1,
664
+ scheduler: abc.SchedulerBase | None = None,
665
+ ) -> Observable[str]:
666
+ """Convert to marble diagram.
667
+
668
+ Convert an observable sequence into a marble diagram string.
669
+
670
+ Examples:
671
+ Fluent style:
672
+ >>> result = source.to_marbles()
673
+ >>> result = source.to_marbles(0.2)
674
+
675
+ Equivalent pipe style:
676
+ >>> from reactivex import operators as ops
677
+ >>> result = source.pipe(ops.to_marbles())
678
+
679
+ Args:
680
+ timespan: Duration of each time slot in seconds.
681
+ scheduler: Scheduler to use for timing.
682
+
683
+ Returns:
684
+ An observable sequence with a single value of a marble diagram
685
+ string.
686
+
687
+ See Also:
688
+ - :func:`to_marbles <reactivex.operators.to_marbles>`
689
+ """
690
+ from reactivex import operators as ops
691
+
692
+ return self._as_observable().pipe(ops.to_marbles(timespan, scheduler))
693
+
694
+ def delay_with_mapper(
695
+ self,
696
+ subscription_delay: Observable[Any]
697
+ | typing.Mapper[Any, Observable[Any]]
698
+ | None = None,
699
+ delay_duration_mapper: typing.Mapper[_T, Observable[Any]] | None = None,
700
+ ) -> Observable[_T]:
701
+ """Delay with mapper functions.
702
+
703
+ Time shifts the observable sequence based on a subscription delay and
704
+ a delay mapper function for each element.
705
+
706
+ Examples:
707
+ Fluent style:
708
+ >>> result = source.delay_with_mapper(
709
+ ... subscription_delay=rx.timer(1.0),
710
+ ... delay_duration_mapper=lambda x: rx.timer(x * 0.1)
711
+ ... )
712
+
713
+ Equivalent pipe style:
714
+ >>> from reactivex import operators as ops
715
+ >>> result = source.pipe(
716
+ ... ops.delay_with_mapper(
717
+ ... subscription_delay=rx.timer(1.0),
718
+ ... delay_duration_mapper=lambda x: rx.timer(x * 0.1)
719
+ ... )
720
+ ... )
721
+
722
+ Args:
723
+ subscription_delay: Observable indicating the delay for the
724
+ subscription, or a function that returns such an observable.
725
+ delay_duration_mapper: Selector function to retrieve an observable
726
+ for each element that determines its delay.
727
+
728
+ Returns:
729
+ Time-shifted sequence.
730
+
731
+ See Also:
732
+ - :func:`delay_with_mapper <reactivex.operators.delay_with_mapper>`
733
+ - :meth:`delay`
734
+ """
735
+ from reactivex import operators as ops
736
+
737
+ return self._as_observable().pipe(
738
+ ops.delay_with_mapper(subscription_delay, delay_duration_mapper)
739
+ )
740
+
741
+ def timeout_with_mapper(
742
+ self,
743
+ first_timeout: Observable[Any] | None = None,
744
+ timeout_duration_mapper: typing.Mapper[_T, Observable[Any]] | None = None,
745
+ other: Observable[_T] | None = None,
746
+ ) -> Observable[_T]:
747
+ """Timeout with mapper functions.
748
+
749
+ Returns the source observable sequence, switching to the other
750
+ observable sequence if a timeout is signaled.
751
+
752
+ Examples:
753
+ Fluent style:
754
+ >>> result = source.timeout_with_mapper(
755
+ ... first_timeout=rx.timer(5.0),
756
+ ... timeout_duration_mapper=lambda x: rx.timer(1.0)
757
+ ... )
758
+
759
+ Equivalent pipe style:
760
+ >>> from reactivex import operators as ops
761
+ >>> result = source.pipe(
762
+ ... ops.timeout_with_mapper(
763
+ ... first_timeout=rx.timer(5.0),
764
+ ... timeout_duration_mapper=lambda x: rx.timer(1.0)
765
+ ... )
766
+ ... )
767
+
768
+ Args:
769
+ first_timeout: Observable that triggers timeout for the first
770
+ element.
771
+ timeout_duration_mapper: Selector to retrieve an observable that
772
+ triggers timeout for each element.
773
+ other: Sequence to return in case of a timeout.
774
+
775
+ Returns:
776
+ The source sequence switching to the other sequence in case of a
777
+ timeout.
778
+
779
+ See Also:
780
+ - :func:`timeout_with_mapper <reactivex.operators.timeout_with_mapper>`
781
+ - :meth:`timeout`
782
+ """
783
+ from reactivex import operators as ops
784
+
785
+ return self._as_observable().pipe(
786
+ ops.timeout_with_mapper(first_timeout, timeout_duration_mapper, other)
787
+ )
788
+
789
+ def as_observable(self) -> Observable[_T]:
790
+ """Hide the identity of the observable.
791
+
792
+ Hides the identity of an observable sequence.
793
+
794
+ Examples:
795
+ Fluent style:
796
+ >>> result = source.as_observable()
797
+
798
+ Equivalent pipe style:
799
+ >>> from reactivex import operators as ops
800
+ >>> result = source.pipe(ops.as_observable())
801
+
802
+ Returns:
803
+ An observable sequence that hides the identity of the source
804
+ sequence.
805
+
806
+ See Also:
807
+ - :func:`as_observable <reactivex.operators.as_observable>`
808
+ """
809
+ from reactivex import operators as ops
810
+
811
+ return self._as_observable().pipe(ops.as_observable())