ops.group_by(key_selector) ) groups.subscribe(subscribe_group_observable) # Sample: A way to grab items and emit latest values at certain points print('-- Sample') # 10 ms 마다 인터벌 발생 (시간의 단위는 초이다.) rx.interval(0.01).pipe( # 1초 동안 동작 ops.take_until(rx.timer(1)), # 100ms 마다 이벤트 출력 (현재 받은 최신값) ops.sample(0.1) ).subscribe(print) time.sleep(2) # Max print('-- Max') rx.from_([1, 2, 3, 4, 12, 3, 3, -10]).pipe( ops.max(lambda x, y: x - y) ).subscribe(print)
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.map(lambda v: v[1]), 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()
"""this operator will given an observable with max 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 max value from the source observable. """ from rx import of, operators as op o = of(12, 24, 50, 33, 72, 80, 520, 1001) o.pipe( # op.max(), # Max value is 1001 # op.max(lambda t1, t2: t1 - t2), # Max value is 1001 op.max(lambda t1, t2: t2 - t1) # Max value is 12 # java compare o1, o2와 같다. ).subscribe(lambda r: print("Max value is {}".format(r)))
import rx import rx.operators as ops numbers = rx.from_([1, 2, 3, 4]) numbers.pipe(ops.max()).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"))
files = ['test.csv', 'test2.csv'] source = rx.from_([rx.from_(read_csv(filename)) for filename in files]).pipe(ops.merge_all(), ops.map(row_to_dict)) published = source.pipe(ops.publish()) def print_row(row): print( 'File: {filename} has {lines} lines and its size is {size} kb'.format( **row)) def print_group(group): return group.subscribe(print_row) # 두 곳에서 subscribe 한다. #1 maximum = published.pipe(ops.max(lambda a, b: a['lines'] - b['lines'])) maximum.subscribe(lambda row: print( '-- File with the most number of lines is "{filename}" with {lines} lines'. format(**row))) # 2 published.pipe(ops.group_by(lambda row: row['size'])).subscribe(print_group) # 이걸 해야 시작 published.connect()
def create(): return xs.pipe(ops.max(reverse_comparer))
def create(): return xs.pipe(ops.max())