Skip to content

Instantly share code, notes, and snippets.

@Winterflower
Created February 4, 2017 15:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Winterflower/ea8b96bdc0f5f0f262293c6da6ba8fef to your computer and use it in GitHub Desktop.
Save Winterflower/ea8b96bdc0f5f0f262293c6da6ba8fef to your computer and use it in GitHub Desktop.
Simple example of RxPy usage
"""
Simple RxPy example
"""
from rx import Observer, Observable
from numpy import random
class DataAnalyser(Observer):
#a class for analyzing data
def on_next(self, value):
if value<=3:
print('Safe to enjoy the outdoors!')
else:
print('Air pollution is high in your area - please take care!')
def on_completed(self):
print('Finished analyzing pollution data')
def on_error(self, error):
print('Something went wrong in data analysis')
def main():
air_pollution_indices = Observable.from_([random.randint(1,10) for _ in range(20)])
data_analyser = DataAnalyser()
air_pollution_indices.subscribe(data_analyser)
if __name__=='__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment