Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

What is the difference between an observable and a generator?


Asked by Lucia Barnett on Dec 08, 2021 FAQ



An Observable is a Producer of multiple values, "pushing" them to Observers (Consumers). A Function is a lazily evaluated computation that synchronously returns a single value on invocation. A generator is a lazily evaluated computation that synchronously returns zero to (potentially) infinite values on iteration.
In this manner,
Observable.create (observer => observer.next (myArray)) will fire onNext event once to return myArray whereas Observable.from (myArray) will emit many onNext events to return one item each time. One difference is: Observable.from () specifically forbids null as something it accepts.
Moreover, A Function is a lazily evaluated computation that synchronously returns a single value on invocation. A generator is a lazily evaluated computation that synchronously returns zero to (potentially) infinite values on iteration. A Promise is a computation that may (or may not) eventually return a single value.
Additionally,
The main aspect you should understand is that Observable is just a function that relates Observer and Data Producer. Here is the code example for better understanding: In this example you can see emitValue function puts Observer inside and every second emits increased value by calling next method from Observer object.
Indeed,
Hamiltonians are observables. (The observed value is the energy.) Observables are Hermitian operators. (and every Hermitian operator defines an observable.) i times a Hermitian operator is an anti-Hermitian operator, and conversely.