Rxjs: difference between Observable. First vs Single vs Filter

I am learning the RxJS library and am really a fan of using Observable instead of Promise. However, can anyone provide detailed information on the difference between use

  • Observable.First
  • Observable.Single
  • Apply filter so that it returns only one item

What is the need for Single in this library?

+6
source share
1 answer

If by filter you mean something like:

let emitted = false;
obs = obs.filter(x => {
  if(emitted) {
    return false;
  } else {
    emitted = true;
    return true;
  }
});

Filter (in this particular case, check the code above)

Will issue as soon as the first item appears. Will ignore all subsequent paragraphs. Finishes when the source object completes.

in : -1-2-3--|---
out: -1------|---

The first

, . .

in : -1-2-3--|---
out: -1|----------

, .

in : -1-2-3--|---
out: -1-X---------

, ( single , ). .

in : -1------|---
out: --------1|--
+10

Source: https://habr.com/ru/post/1664555/


All Articles