In [2]:
%run startup.py
In [3]:
%%javascript
$.getScript('./assets/js/ipython_notebook_toc.js')
source: http://reactivex.io/documentation/operators.html#tree.
(transcribed to RxPY 1.5.7, Py2.7 / 2016-12, Gunther Klessinger, axiros)
This tree can help you find the ReactiveX Observable operator you’re looking for.
See Part 1 for Usage and Output Instructions.
We also require acquaintance with the marble diagrams feature of RxPy.
In [7]:
rst(O.all)
for i in 9, 10:
d = subs(O.range(10, 20).all(lambda v: v > i))
In [19]:
rst(O.contains)
d = subs(O.range(10, 20).contains(11))
header("equality operation")
d = subs(O.range(10, 20).contains(11, comparer=lambda x, y: y == x + 1))
In [42]:
def comparer(*a):
''' find_index: you get value, index and the observable itself as argument
some: you get only the value
'''
log('comparer args:', *a)
l.append(1)
if len(l) > 3:
# => index will be 0
return True
stream = O.from_((4, 1, 2, 1, 3))
for name in 'find_index', 'some':
l = []
operator = getattr(stream, name)
rst(operator) # output documentation, reset timer
d = subs(operator(lambda *a: comparer(*a)))
In [45]:
rst(O.is_empty)
d = subs(O.from_([]).is_empty())
In [75]:
rst(O.sequence_equal)
def f(x, y):
log('got', x, y)
return str(y) == str(x).upper()
d = subs(O.from_('rxpy rocks').sequence_equal(
O.from_('RXPY ROCKS'), lambda x, y: f(x, y)))
header("there is no order guarantee of arguments in the comparer:")
d = subs(marble_stream('a-b------c-d|').sequence_equal(
marble_stream('A-B----C-D|'), lambda x, y: f(x, y)))
In [83]:
rst(O.average)
d = subs(O.from_('1199').average(lambda x: int(x)))
In [84]:
rst(O.sum)
d = subs(O.from_('1199').sum(lambda x: int(x)))
In [88]:
rst(O.count)
d = subs(O.from_('1199').count(lambda x: int(x) > 2))
In [91]:
rst(O.max)
d = subs(O.from_('1199').max(lambda x, y: int(x) + int(y) < 5))
In [97]:
rst(O.max_by)
d = subs(O.from_('1271246').max_by(lambda x: int(x) < 5))
In [99]:
rst(O.min)
d = subs(O.from_('1199').min(lambda x, y: int(x) + int(y) > 5))
In [100]:
rst(O.min_by)
d = subs(O.from_('1271246').min_by(lambda x: int(x) < 5))
In [110]:
rst(O.scan)
# printing original value next to the aggregate:
d = subs(O.from_('12345').scan(
lambda x, y: [y, int(x[1]) + int(y)],
seed=[0, 0]))
In [115]:
rst(O.expand)
# printing original value next to the aggregate:
d = subs(O.just(42).expand(lambda x: O.just(42 + x)).take(5))
In [ ]: