def create(): def mapper(ys, i): def proj(y): return "%s %s" % (i, y) return ys.pipe(ops.map(proj), ops.concat(rx.return_value('%s end' % i))) return xs.pipe(ops.window_with_time(100, 50), ops.map_indexed(mapper), ops.merge_all())
def _buffer_with_time(timespan: typing.RelativeTime, timeshift: typing.RelativeTime = None, scheduler: typing.Scheduler = None) -> Callable[[Observable], Observable]: if not timeshift: timeshift = timespan return pipe( ops.window_with_time(timespan, timeshift, scheduler), ops.flat_map(lambda x: x.pipe(ops.to_iterable())) )
def _buffer_with_time( timespan: typing.RelativeTime, timeshift: Optional[typing.RelativeTime] = None, scheduler: Optional[typing.Scheduler] = None ) -> Callable[[Observable], Observable]: if not timeshift: timeshift = timespan return pipe(ops.window_with_time(timespan, timeshift, scheduler), ops.flat_map(lambda x: x.pipe(ops.to_iterable())))
def create(): def mapper(w, i): return w.pipe(ops.map(lambda x: "%s %s" % (i, x))) return xs.pipe(ops.window_with_time(100, 70), ops.map_indexed(mapper), ops.merge_all())
def stream(self): return self.subject_.pipe( ops.window_with_time(self.window), ops.map(lambda x: x.pipe(ops.average(), ops.first())), ops.merge_all() )
# observable=[3] print('-- window_with_count | FlatMap') rx.from_(range(3)).pipe(ops.window_with_count(2), ops.flat_map(lambda x: x)).subscribe(print_value) # flatmap 은 # flat 하면 리스트를 푼다. # [[1,2], [3]] -> [1,2,3] # 그리고 나서 map 한다. x -> x # [1, 2, 3] -> [1, 2, 3] print('-- window_with_time') test_scheduler = TestScheduler() rx.interval(0.05, test_scheduler).pipe(ops.take_until( rx.timer(0.1)), ops.window_with_time(0.01)).subscribe( lambda observable: observable.pipe(ops.count()).subscribe(print_value)) test_scheduler.start() time.sleep(0.5) # 결과가 이게 맞나?? 단위가 뭐지? print('-- combine_latest') rx.combine_latest( rx.interval(0.1).pipe(ops.map(lambda x: 'a- {}'.format(x))), rx.interval(0.2).pipe(ops.map(lambda x: 'b- {}'.format(x)))).pipe( ops.take_until(rx.timer(0.5))).subscribe(print_value) time.sleep(1) # 누가 먼저 결과를 배출할지 예상 불가 print('-- zip') rx.zip(