[英]reactive programming store result in a variable
quick (trivial) question: I cannot find a way to store the output of a series of operation on an observable in an external variable. 快速(琐碎的)问题:我找不到在外部变量中将可观察的一系列操作的输出存储的方法。 For instance something like that: 例如这样的事情:
mylist = []
Observable.from_([1, 2, 3]).to_list().store(mylist)
Not sure this is very "reactive", but should be trivial. 不确定这是否“很活跃”,但应该微不足道。
Thanks in advance 提前致谢
C C
Here is a solution i found: 这是我找到的解决方案:
mylist = []
def store(value):
mylist.append(value)
Observable.from_([1, 2, 3]).do_action(store).subscribe()
print(mylist)
Comments? 评论?
Thanks 谢谢
Turn your observable into a blocking one via .to_blocking()
. 通过.to_blocking()
将您的可观察对象变成阻塞.to_blocking()
。 Now you can iterate over it. 现在您可以对其进行迭代。
mylist=list(Observable.from_([1, 2, 3]).to_blocking())
print(mylist)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.