Q:

Observables Basics

I believe I have a use case which is appropriate for Observables but I'm not sure how to implement as Observables are not the most intuitive concept.
Lets say I have 3 numbers: let a: number, b: number, c: number; and I want to monitor them as they change. if((a + b + c) / 3 === 0)) return true else false. How can I create an observer  that will monitor those numbers and using it I can get the boolean value?

A:

Here's an example. In real life aSubject, bSubject, and cSubject are regular Observable streams that you either construct, or get from your framework or choice, etc.
In my demo, I use BehaviorSubjects, because technically speaking, Subjects are Observables.
The Setup part of the code creates the three source streams, and the formulaObservable that checks whether the sum of the last known values of a, b, c, divided by 3 is 0. Notice that aSubject.next(1) is somewhat similar in a sense to a = 1 in "normal" JS. The key difference is that .next() is creating an even in the Observable stream.
The combineLatest() operator creates a new Observable that looks at n input Observable streams and calculates some function of last known values of those n streams.
import { Observable, BehaviorSubject } from 'rxjs';

// "Setup"

const aSubject = new BehaviorSubject<number | undefined>(undefined);
const bSubject = new BehaviorSubject<number | undefined>(undefined);
const cSubject = new BehaviorSubject<number | undefined>(undefined);

const formulaObservable = Observable
  .combineLatest(
    aSubject,
    bSubject,
    cSubject,
  )
  .map(values => {
    const [a, b, c] = values;
    if (a == null || b == null || c == null) {
      return Observable.never();
    } else {
      return (a + b + c) / 3 === 0;
    }
  });

formulaObservable.subscribe(result => console.warn(`Result: ${result}`));

// ---
// "Usage"

aSubject.next(1);
bSubject.next(2);
cSubject.next(1); // a===1, b===2,         c===1,         formulaObservable==Observable.of(false)
bSubject.next(1); // a===1, b===1,         c===1,         formulaObservable==Observable.of(true)

Hope, it helps.

P.S. You can play with the interactive RxJsMarbles to understand how they work better. Notice that the colored balls are draggable.
P.P.S. This is an okay question, but I think your downvotes are coming from either the fact you didn't do the research (no code posted along the question itself), or because you didn't search on StackOverflow.

