示例#1
0
 def test_min_int32_on_error(self):
     ex = 'ex'
     scheduler = TestScheduler()
     xs = scheduler.create_hot_observable(on_next(150, 1),
                                          on_error(210, ex))
     res = scheduler.start(create=lambda: xs.pipe(ops.min())).messages
     assert res == [on_error(210, ex)]
示例#2
0
 def test_min_int32_some(self):
     scheduler = TestScheduler()
     xs = scheduler.create_hot_observable(
             on_next(150, 1), on_next(210, 2), on_next(220, 3),
             on_next(230, 4), on_completed(250))
     res = scheduler.start(create=lambda: xs.pipe(ops.min())).messages
     assert res == [on_next(250, 2), on_completed(250)]
示例#3
0
 def test_min_int32_some(self):
     scheduler = TestScheduler()
     xs = scheduler.create_hot_observable(on_next(150, 1), on_next(210, 2),
                                          on_next(220, 3), on_next(230, 4),
                                          on_completed(250))
     res = scheduler.start(create=lambda: xs.pipe(ops.min())).messages
     assert res == [on_next(250, 2), on_completed(250)]
示例#4
0
import rx
import rx.operators as ops

numbers = rx.from_([1, 2, 3, 4])

numbers.pipe(ops.min()).subscribe(
    on_next=lambda i: print("on_next {}".format(i)),
    on_error=lambda e: print("on_error: {}".format(e)),
    on_completed=lambda: print("on_completed"))
示例#5
0
    op.average()
).subscribe(reporter)

print('=' * 25)


stocks2 = (('GOOG', 8.95), ('APPL', 7.65), ('APPL', 12.45), ('MSFT', 5.66), ('GOOG', 7.56), ('IBM', 12.76))

source1 = rx.from_list(stocks)
source2 = rx.from_list(stocks2)

# Find the max
rx.merge(source1, source2).pipe(
    op.map(lambda v: v[1]),
    op.max()
).subscribe(reporter)

print('-' * 25)

# Find the min
rx.merge(source1, source2).pipe(
    op.map(lambda v: v[1]),
    op.min()
).subscribe(reporter)

print('-' * 25)

# Only publish unique values
rx.merge(source1, source2).pipe(
    op.distinct()
).subscribe(reporter)
示例#6
0
"""this operator will give an observable with min value from the source observable

:parameter
    comparer_function: optional param.
    this function is used on source observables to compare values.

:return
    it returns an observable with min value from the source observable.

"""

from rx import of, operators as op

o = of(12, 32, 41, 52, 62, 502, 555)

o.pipe(
    # op.min(lambda t1, t2: t1 - t2), # Min value is 12
    # op.min(lambda t1, t2: t2 - t1) # Min value is 555
    op.min() # Min value is 12
).subscribe(lambda x: print("Min value is {}".format(x)))

rx.throw()
rx.interval()
rx.from_()
rx.interval()
rx.just()
rx.range()
rx.repeat_value()
rx.start()
rx.timer()

"""Mathematical"""
op.average()
op.concat()
op.count()
op.max()
op.min()
op.reduce()
op.sum()

"""Transformation"""
op.buffer()
op.group_by()
op.map()
op.scan()
# ...

"""Filtering"""
op.debounce()
op.distinct()
op.filter()
op.element_at()
示例#8
0
 def create():
     return xs.pipe(ops.min(comparer))
示例#9
0
 def test_min_int32_never(self):
     scheduler = TestScheduler()
     xs = scheduler.create_hot_observable(on_next(150, 1))
     res = scheduler.start(create=lambda: xs.pipe(ops.min())).messages
     assert res == []
示例#10
0
 def test_min_int32_on_error(self):
     ex = 'ex'
     scheduler = TestScheduler()
     xs = scheduler.create_hot_observable(on_next(150, 1), on_error(210, ex))
     res = scheduler.start(create=lambda: xs.pipe(ops.min())).messages
     assert res == [on_error(210, ex)]
示例#11
0
 def create():
     return xs.pipe(ops.min())
示例#12
0
 def create():
     return xs.pipe(ops.min(comparer))
示例#13
0
 def test_min_int32_never(self):
     scheduler = TestScheduler()
     xs = scheduler.create_hot_observable(on_next(150, 1))
     res = scheduler.start(create=lambda: xs.pipe(ops.min())).messages
     assert res == []
示例#14
0
 def create():
     return xs.pipe(ops.min())