本文整理汇总了Python中rx.core.Observable.from_方法的典型用法代码示例。如果您正苦于以下问题:Python Observable.from_方法的具体用法?Python Observable.from_怎么用?Python Observable.from_使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rx.core.Observable
的用法示例。
在下文中一共展示了Observable.from_方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: variance
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import from_ [as 别名]
def variance(source: ObservableBase) -> ObservableBase:
"""
Returns the statistical variance of the numerical emissions.
The sequence must be finite.
"""
squared_values = source.to_list() \
.flat_map(lambda l: Observable.from_(l).average().flat_map(lambda avg: Observable.from_(l).map(lambda i: i - avg))) \
.map(lambda i: i * i) \
.publish() \
.auto_connect(2)
return Observable.zip(squared_values.sum(), squared_values.count(), lambda sum, ct: sum / (ct - 1))
示例2: merge
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import from_ [as 别名]
def merge(cls, *args):
"""Merges all the observable sequences into a single observable
sequence. The scheduler is optional and if not specified, the
immediate scheduler is used.
1 - merged = rx.Observable.merge(xs, ys, zs)
2 - merged = rx.Observable.merge([xs, ys, zs])
3 - merged = rx.Observable.merge(scheduler, xs, ys, zs)
4 - merged = rx.Observable.merge(scheduler, [xs, ys, zs])
Returns the observable sequence that merges the elements of the
observable sequences.
"""
if not args[0]:
scheduler = immediate_scheduler
sources = args[1:]
elif isinstance(args[0], Scheduler):
scheduler = args[0]
sources = args[1:]
else:
scheduler = immediate_scheduler
sources = args[:]
if isinstance(sources[0], list):
sources = sources[0]
return Observable.from_(sources, scheduler).merge_all()
示例3: test_time_interval_default_scheduler
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import from_ [as 别名]
def test_time_interval_default_scheduler(self):
import datetime
xs = Observable.from_((1,2)).time_interval().pluck_attr('interval')
l = []
d = xs.subscribe(lambda x: l.append(x))
self.assertEqual(len(l), 2)
[self.assertIsInstance(el, datetime.timedelta) for el in l]
示例4: mode
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import from_ [as 别名]
def mode(source: ObservableBase) -> ObservableBase:
"""
Returns the most frequently emitted value (or "values" if they have the same number of occurrences).
The sequence must be finite.
"""
return source.group_by(lambda v: v) \
.flat_map(lambda grp: grp.count().map(lambda ct: (grp.key, ct))) \
.to_sorted_list(lambda t: t[1], reverse=True) \
.flat_map(lambda l: Observable.from_(l).take_while(lambda t: t[1] == l[0][1])) \
.map(lambda t: t[0])
示例5: go
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import from_ [as 别名]
def go():
scheduler = AsyncIOScheduler()
xs = Observable.from_([x for x in range(10)], scheduler=scheduler)
gen = xs.to_async_generator()
# Wish we could write something like:
# ys = (x for x in yield from gen())
while True:
x = yield from gen()
if x is None:
break
print(x)
示例6: start_with
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import from_ [as 别名]
def start_with(self, *args, **kw):
"""Prepends a sequence of values to an observable sequence with an
optional scheduler and an argument list of values to prepend.
1 - source.start_with(1, 2, 3)
2 - source.start_with(Scheduler.timeout, 1, 2, 3)
Returns the source sequence prepended with the specified values.
"""
if isinstance(args[0], Scheduler):
scheduler = args[0]
args = args[1:]
else:
scheduler = kw.get("scheduler", immediate_scheduler)
sequence = [Observable.from_(args, scheduler), self]
return Observable.concat(sequence)
示例7: action1
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import from_ [as 别名]
def action1(scheduler, state):
xs[0] = Observable.from_(["alpha", "apple", "beta", "bat", "gamma"]) \
.group_by(lambda s: s[0]) \
.map(lambda group: group.to_list()) \
.merge_all()