0

I'm new to ReactiveX and I have a question. How can I save data in ReactiveX. For example. I have this code.

last_price = market_data_service.get_last_price("IBM")
difference = previous_last_price - last_price 

For its correct work, I need to know the previous value of the price. How can I save the previous price in ReactiveX.

user45245
  • 845
  • 1
  • 8
  • 18
  • 2
    What does it mean "save data"? Rx has some operators, that collects previous emisions(collect, scan). Are you sure, that reactive streams suitable for your task? – zella Jul 10 '18 at 16:57

1 Answers1

0

In RX methods returns Observable<T>. So in your case, above should be:

int previous_last_price = 10;
Single<Integer> market_data_service = Single.just(5);
Single<Integer> difference = market_data_service.map(last_price -> previous_last_price - last_price);
Niraj Chauhan
  • 7,677
  • 12
  • 46
  • 78