{"id":324702,"date":"2021-06-10T15:00:16","date_gmt":"2021-06-10T15:00:16","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=324702"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=324702","title":{"rendered":"\u041a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b RxJS"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 RxJS \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0448\u0438\u0440\u043e\u043a\u043e\u043c\u0443 \u0432\u044b\u0431\u043e\u0440\u0443 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u043f\u043e \u043f\u0440\u0430\u0432\u0443 \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043a\u0440\u0430\u0439\u043d\u0435 \u043c\u043e\u0449\u043d\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0432 \u0430\u0440\u0441\u0435\u043d\u0430\u043b\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430. \u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u044f \u0445\u043e\u0447\u0443 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432\u0430\u043c \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044e \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 RxJS \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.  <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d28\/22a\/502\/d2822a502e7458e0a9aebf1dc282af98.png\" width=\"780\" height=\"439\"><figcaption><\/figcaption><\/figure>\n<p><a href=\"https:\/\/rxjs-dev.firebaseapp.com\/\"><u>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 RxJS<\/u><\/a> \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0448\u0438\u0440\u043e\u043a\u043e\u043c\u0443 \u0432\u044b\u0431\u043e\u0440\u0443 <a href=\"https:\/\/indepth.dev\/reference\/rxjs\/operators\"><u>\u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432<\/u><\/a> \u043f\u043e \u043f\u0440\u0430\u0432\u0443 \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043a\u0440\u0430\u0439\u043d\u0435 \u043c\u043e\u0449\u043d\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0432 \u0430\u0440\u0441\u0435\u043d\u0430\u043b\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430. \u041d\u0435\u0434\u0430\u0432\u043d\u043e \u044f \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0430\u043c\u043e\u043f\u0438\u0441\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432. \u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u044f \u0445\u043e\u0447\u0443 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432\u0430\u043c \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044e \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 RxJS \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<h3>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438<\/h3>\n<p>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 RxJS&nbsp;\u2014 \u044d\u0442\u043e \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0435\u0440\u0435\u0442 \u043d\u0435\u043a\u0438\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u044b\u0435 (observable) \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043f\u043e\u0442\u043e\u043a. \u0421\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 RxJS \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 JavaScript (TypeScript). \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 (identity), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0435\u0440\u043a\u0430\u043b\u0438\u0440\u0443\u0435\u0442 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u044b\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435:<\/p>\n<pre><code class=\"javascript\">import { interval, Observable } from \"rxjs\"; import { take } from \"rxjs\/operators\";  const source$ = interval(1000).pipe(take(3));  function identity&lt;T&gt;(source$: Observable&lt;T&gt;): Observable&lt;T&gt; {   return source$; }  const results$ = source$.pipe(identity);  results$.subscribe(console.log);    \/\/ console output: 0, 1, 2<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u0441 \u043a\u043e\u0435-\u043a\u0430\u043a\u043e\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u043e\u0439.<\/p>\n<h3>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/h3>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043f\u043e\u0431\u043e\u0447\u043d\u043e\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 (\u043b\u043e\u0433\u0438\u0440\u0443\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438) \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430:<\/p>\n<pre><code class=\"javascript\">&lt;&gt;Copy import { interval, Observable } from \"rxjs\"; import { take, tap } from \"rxjs\/operators\";  const source$ = interval(1000).pipe(take(3));  function log&lt;T&gt;(source$: Observable&lt;T&gt;): Observable&lt;T&gt; {   return source$.pipe(tap(v =&gt; console.log(`log: ${v}`))); }  const results$ = source$.pipe(log);  results$.subscribe(console.log);    \/\/ console output: log: 0, log: 1, log: 2<\/code><\/pre>\n<p>\u0412 \u043e\u0441\u043d\u043e\u0432\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \u043b\u0435\u0436\u0430\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 <em>source$<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0438\u0434\u043e\u0438\u0437\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0432 \u0441\u043e\u0441\u0442\u0430\u0432\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 pipe.<\/p>\n<h3>\u0424\u0430\u0431\u0440\u0438\u043a\u0430 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430<\/h3>\n<p>\u0412 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f\u0445 \u0434\u043b\u044f \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440. \u0410\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u0432\u0445\u043e\u0434\u044f\u0442 \u0432 \u043b\u0435\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430:<\/p>\n<pre><code class=\"javascript\">import { interval, Observable } from \"rxjs\"; import { take, tap } from \"rxjs\/operators\";  const source$ = interval(1000).pipe(take(3));  function logWithTag&lt;T&gt;(tag: string): (source$: Observable&lt;T&gt;) =&gt; Observable&lt;T&gt; {   return source$ =&gt;     source$.pipe(tap(v =&gt; console.log(`logWithTag(${tag}): ${v}`))); }  const results$ = source$.pipe(logWithTag(\"RxJS\"));  results$.subscribe(console.log);    \/\/ console output: logWithTag(RxJS): 0, logWithTag(RxJS): 1, logWithTag(RxJS): 2<\/code><\/pre>\n<p>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043c\u043e\u0436\u043d\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c, \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0432\u0448\u0438\u0441\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <a href=\"https:\/\/rxjs-dev.firebaseapp.com\/api\/index\/interface\/MonoTypeOperatorFunction\"><u>MonoTypeOperatorFunction<\/u><\/a> \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438&nbsp;RxJS. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/rxjs-dev.firebaseapp.com\/api\/index\/function\/pipe\"><strong><u>\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 pipe<\/u><\/strong><\/a> \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430:<\/p>\n<pre><code class=\"javascript\">import { interval, MonoTypeOperatorFunction, pipe } from \"rxjs\"; import { take, tap } from \"rxjs\/operators\";  const source$ = interval(1000).pipe(take(3));  function logWithTag&lt;T&gt;(tag: string): MonoTypeOperatorFunction&lt;T&gt; {   return pipe(tap(v =&gt; console.log(`logWithTag(${tag}): ${v}`))); }  const results$ = source$.pipe(logWithTag(\"RxJS\"));  results$.subscribe(console.log);    \/\/ console output: logWithTag(RxJS): 0, logWithTag(RxJS): 1, logWithTag(RxJS): 2<\/code><\/pre>\n<p>\u0414\u0440\u0443\u0433\u0438\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u043e\u0432\u0435\u0442\u044b \u043f\u043e RxJS \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/medium.com\/javascript-everyday\/7-things-you-might-not-know-about-rxjs-66e2e5d57df2\"><u>\u0437\u0434\u0435\u0441\u044c<\/u><\/a>.<\/p>\n<h3>\u0423\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u044f \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044f \u043b\u0435\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438<\/h3>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u0442\u043e\u043a\u0430. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0443 \u0432\u0441\u0435\u0445 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u0435\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0449\u0430\u044f \u043b\u0435\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"javascript\">import { interval, MonoTypeOperatorFunction, pipe } from \"rxjs\"; import { take, tap } from \"rxjs\/operators\";  const source$ = interval(1000).pipe(take(3));  function tapOnce&lt;T&gt;(job: Function): MonoTypeOperatorFunction&lt;T&gt; {   let isFirst = true;    return pipe(     tap(v =&gt; {       if (!isFirst) {         return;       }        job(v);       isFirst = false;     })   ); }  const results$ = source$.pipe(tapOnce(() =&gt; console.log(\"First value emitted\")));  results$.subscribe(console.log); results$.subscribe(console.log);    \/\/ console output: First value emitted, 0, 0, 1, 1, 2, 2<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044f \u0431\u044b\u043b\u0430 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u0430\u044f \u043b\u0435\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c <a href=\"https:\/\/rxjs-dev.firebaseapp.com\/api\/index\/function\/defer\"><u>\u0444\u0443\u043d\u043a\u0446\u0438\u044e defer<\/u><\/a>:<\/p>\n<pre><code class=\"javascript\">import { defer, interval, MonoTypeOperatorFunction } from \"rxjs\"; import { take, tap } from \"rxjs\/operators\";  const source$ = interval(1000).pipe(take(3));  function tapOnceUnique&lt;T&gt;(job: Function): MonoTypeOperatorFunction&lt;T&gt; {   return source$ =&gt;     defer(() =&gt; {       let isFirst = true;        return source$.pipe(         tap(v =&gt; {           if (!isFirst) {             return;           }            job(v);           isFirst = false;         })       );     }); }  const results$ = source$.pipe(tapOnceUnique(() =&gt; console.log(\"First value emitted\")));  results$.subscribe(console.log); results$.subscribe(console.log);    \/\/ console output: First value emitted, 0, First value emitted, 0, 1, 1, 2, 2<\/code><\/pre>\n<p>\u0414\u0440\u0443\u0433\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 <code>tapOnce<\/code> \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432 <a href=\"https:\/\/medium.com\/javascript-everyday\/rxjs-taponce-operator-yet-another-solution-435f88e2484a\"><u>\u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u043c\u043e\u0438\u0445 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u043f\u043e\u0441\u0442\u043e\u0432<\/u><\/a>.<\/p>\n<h3>\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b<\/h3>\n<p>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>firstTruthy<\/code>:<\/p>\n<pre><code class=\"javascript\">import { MonoTypeOperatorFunction, of, pipe } from \"rxjs\"; import { first } from \"rxjs\/operators\";  const source1$ = of(0, \"\", \"foo\", 69);  function firstTruthy&lt;T&gt;(): MonoTypeOperatorFunction&lt;T&gt; {   return pipe(first(v =&gt; Boolean(v))); }  const result1$ = source1$.pipe(firstTruthy());  result1$.subscribe(console.log);  \/\/ console output: foo<\/code><\/pre>\n<p>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>evenMultiplied<\/code>:<\/p>\n<pre><code class=\"javascript\">import { interval, MonoTypeOperatorFunction, pipe } from \"rxjs\"; import { filter, map, take } from \"rxjs\/operators\";  const source2$ = interval(10).pipe(take(3));  function evenMultiplied(multiplier: number): MonoTypeOperatorFunction&lt;number&gt; {   return pipe(     filter(v =&gt; v % 2 === 0),     map(v =&gt; v * multiplier)   ); }  const result2$ = source2$.pipe(evenMultiplied(3));  result2$.subscribe(console.log);    \/\/ console output: 0, 6<\/code><\/pre>\n<p>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>liveSearch<\/code>:<\/p>\n<pre><code class=\"javascript\">import { ObservableInput, of, OperatorFunction, pipe  } from \"rxjs\"; import { debounceTime, delay, distinctUntilChanged, switchMap } from \"rxjs\/operators\";  const source3$ = of(\"politics\", \"sport\");  type DataProducer&lt;T&gt; = (q: string) =&gt; ObservableInput&lt;T&gt;;  function liveSearch&lt;R&gt;(   time: number,   dataProducer: DataProducer&lt;R&gt; ): OperatorFunction&lt;string, R&gt; {   return pipe(     debounceTime(time),     distinctUntilChanged(),     switchMap(dataProducer)   ); }  const newsProducer = (q: string) =&gt;   of(`Data fetched for ${q}`).pipe(delay(2000));  const result3$ = source3$.pipe(liveSearch(500, newsProducer));  result3$.subscribe(console.log);    \/\/ console output: Data fetched for sport<\/code><\/pre>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0422\u0438\u043f\u043e\u0432\u044b\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 RxJS \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0432 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0438 \u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u043f\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430. \u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u0432 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c\u044b\u0445 \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 pipe-\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>\u0416\u0438\u0432\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440: [\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0432 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u0435]<\/p>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0432\u0430\u043c \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u043b\u0441\u044f \u043c\u043e\u0439 \u043f\u043e\u0441\u0442 \u0438 \u0432\u044b \u0443\u0437\u043d\u0430\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u043d\u043e\u0432\u043e\u0435.<\/p>\n<hr>\n<blockquote>\n<p>\u041f\u0435\u0440\u0435\u0432\u043e\u0434 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043a\u0443\u0440\u0441\u0430 &#171;<a href=\"https:\/\/otus.pw\/cm96\/\"><strong>JavaScript Developer. Professional<\/strong><\/a>&#171;. \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u043e \u043a\u0443\u0440\u0441\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435, \u043f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u0435\u043c \u043d\u0430 <a href=\"https:\/\/otus.pw\/hAV6\/\">\u0434\u0435\u043d\u044c \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0445 \u0434\u0432\u0435\u0440\u0435\u0439<\/a> \u043e\u043d\u043b\u0430\u0439\u043d, \u0433\u0434\u0435 \u043f\u0440\u0435\u043f\u043e\u0434\u0430\u0432\u0430\u0442\u0435\u043b\u044c \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0435\u0442 \u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435.<\/p>\n<\/blockquote>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/562184\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/562184\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 RxJS \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0448\u0438\u0440\u043e\u043a\u043e\u043c\u0443 \u0432\u044b\u0431\u043e\u0440\u0443 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u043f\u043e \u043f\u0440\u0430\u0432\u0443 \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043a\u0440\u0430\u0439\u043d\u0435 \u043c\u043e\u0449\u043d\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0432 \u0430\u0440\u0441\u0435\u043d\u0430\u043b\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430. \u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u044f \u0445\u043e\u0447\u0443 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432\u0430\u043c \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044e \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 RxJS \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.  <\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p><a href=\"https:\/\/rxjs-dev.firebaseapp.com\/\"><u>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 RxJS<\/u><\/a> \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0448\u0438\u0440\u043e\u043a\u043e\u043c\u0443 \u0432\u044b\u0431\u043e\u0440\u0443 <a href=\"https:\/\/indepth.dev\/reference\/rxjs\/operators\"><u>\u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432<\/u><\/a> \u043f\u043e \u043f\u0440\u0430\u0432\u0443 \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043a\u0440\u0430\u0439\u043d\u0435 \u043c\u043e\u0449\u043d\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0432 \u0430\u0440\u0441\u0435\u043d\u0430\u043b\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430. \u041d\u0435\u0434\u0430\u0432\u043d\u043e \u044f \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0430\u043c\u043e\u043f\u0438\u0441\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432. \u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u044f \u0445\u043e\u0447\u0443 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432\u0430\u043c \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044e \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 RxJS \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<h3>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438<\/h3>\n<p>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 RxJS&nbsp;\u2014 \u044d\u0442\u043e \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0435\u0440\u0435\u0442 \u043d\u0435\u043a\u0438\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u044b\u0435 (observable) \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043f\u043e\u0442\u043e\u043a. \u0421\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 RxJS \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 JavaScript (TypeScript). \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 (identity), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0435\u0440\u043a\u0430\u043b\u0438\u0440\u0443\u0435\u0442 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u044b\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435:<\/p>\n<pre><code class=\"javascript\">import { interval, Observable } from \"rxjs\"; import { take } from \"rxjs\/operators\";  const source$ = interval(1000).pipe(take(3));  function identity&lt;T&gt;(source$: Observable&lt;T&gt;): Observable&lt;T&gt; {   return source$; }  const results$ = source$.pipe(identity);  results$.subscribe(console.log);    \/\/ console output: 0, 1, 2<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u0441 \u043a\u043e\u0435-\u043a\u0430\u043a\u043e\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u043e\u0439.<\/p>\n<h3>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/h3>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043f\u043e\u0431\u043e\u0447\u043d\u043e\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 (\u043b\u043e\u0433\u0438\u0440\u0443\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438) \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430:<\/p>\n<pre><code class=\"javascript\">&lt;&gt;Copy import { interval, Observable } from \"rxjs\"; import { take, tap } from \"rxjs\/operators\";  const source$ = interval(1000).pipe(take(3));  function log&lt;T&gt;(source$: Observable&lt;T&gt;): Observable&lt;T&gt; {   return source$.pipe(tap(v =&gt; console.log(`log: ${v}`))); }  const results$ = source$.pipe(log);  results$.subscribe(console.log);    \/\/ console output: log: 0, log: 1, log: 2<\/code><\/pre>\n<p>\u0412 \u043e\u0441\u043d\u043e\u0432\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \u043b\u0435\u0436\u0430\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 <em>source$<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0438\u0434\u043e\u0438\u0437\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0432 \u0441\u043e\u0441\u0442\u0430\u0432\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 pipe.<\/p>\n<h3>\u0424\u0430\u0431\u0440\u0438\u043a\u0430 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430<\/h3>\n<p>\u0412 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f\u0445 \u0434\u043b\u044f \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440. \u0410\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u0432\u0445\u043e\u0434\u044f\u0442 \u0432 \u043b\u0435\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430:<\/p>\n<pre><code class=\"javascript\">import { interval, Observable } from \"rxjs\"; import { take, tap } from \"rxjs\/operators\";  const source$ = interval(1000).pipe(take(3));  function logWithTag&lt;T&gt;(tag: string): (source$: Observable&lt;T&gt;) =&gt; Observable&lt;T&gt; {   return source$ =&gt;     source$.pipe(tap(v =&gt; console.log(`logWithTag(${tag}): ${v}`))); }  const results$ = source$.pipe(logWithTag(\"RxJS\"));  results$.subscribe(console.log);    \/\/ console output: logWithTag(RxJS): 0, logWithTag(RxJS): 1, logWithTag(RxJS): 2<\/code><\/pre>\n<p>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043c\u043e\u0436\u043d\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c, \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0432\u0448\u0438\u0441\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <a href=\"https:\/\/rxjs-dev.firebaseapp.com\/api\/index\/interface\/MonoTypeOperatorFunction\"><u>MonoTypeOperatorFunction<\/u><\/a> \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438&nbsp;RxJS. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/rxjs-dev.firebaseapp.com\/api\/index\/function\/pipe\"><strong><u>\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 pipe<\/u><\/strong><\/a> \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430:<\/p>\n<pre><code class=\"javascript\">import { interval, MonoTypeOperatorFunction, pipe } from \"rxjs\"; import { take, tap } from \"rxjs\/operators\";  const source$ = interval(1000).pipe(take(3));  function logWithTag&lt;T&gt;(tag: string): MonoTypeOperatorFunction&lt;T&gt; {   return pipe(tap(v =&gt; console.log(`logWithTag(${tag}): ${v}`))); }  const results$ = source$.pipe(logWithTag(\"RxJS\"));  results$.subscribe(console.log);    \/\/ console output: logWithTag(RxJS): 0, logWithTag(RxJS): 1, logWithTag(RxJS): 2<\/code><\/pre>\n<p>\u0414\u0440\u0443\u0433\u0438\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u043e\u0432\u0435\u0442\u044b \u043f\u043e RxJS \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/medium.com\/javascript-everyday\/7-things-you-might-not-know-about-rxjs-66e2e5d57df2\"><u>\u0437\u0434\u0435\u0441\u044c<\/u><\/a>.<\/p>\n<h3>\u0423\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u044f \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044f \u043b\u0435\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438<\/h3>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u0442\u043e\u043a\u0430. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0443 \u0432\u0441\u0435\u0445 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u0435\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0449\u0430\u044f \u043b\u0435\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"javascript\">import { interval, MonoTypeOperatorFunction, pipe } from \"rxjs\"; import { take, tap } from \"rxjs\/operators\";  const source$ = interval(1000).pipe(take(3));  function tapOnce&lt;T&gt;(job: Function): MonoTypeOperatorFunction&lt;T&gt; {   let isFirst = true;    return pipe(     tap(v =&gt; {       if (!isFirst) {         return;       }        job(v);       isFirst = false;     })   ); }  const results$ = source$.pipe(tapOnce(() =&gt; console.log(\"First value emitted\")));  results$.subscribe(console.log); results$.subscribe(console.log);    \/\/ console output: First value emitted, 0, 0, 1, 1, 2, 2<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044f \u0431\u044b\u043b\u0430 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u0430\u044f \u043b\u0435\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c <a href=\"https:\/\/rxjs-dev.firebaseapp.com\/api\/index\/function\/defer\"><u>\u0444\u0443\u043d\u043a\u0446\u0438\u044e defer<\/u><\/a>:<\/p>\n<pre><code class=\"javascript\">import { defer, interval, MonoTypeOperatorFunction } from \"rxjs\"; import { take, tap } from \"rxjs\/operators\";  const source$ = interval(1000).pipe(take(3));  function tapOnceUnique&lt;T&gt;(job: Function): MonoTypeOperatorFunction&lt;T&gt; {   return source$ =&gt;     defer(() =&gt; {       let isFirst = true;        return source$.pipe(         tap(v =&gt; {           if (!isFirst) {             return;           }            job(v);           isFirst = false;         })       );     }); }  const results$ = source$.pipe(tapOnceUnique(() =&gt; console.log(\"First value emitted\")));  results$.subscribe(console.log); results$.subscribe(console.log);    \/\/ console output: First value emitted, 0, First value emitted, 0, 1, 1, 2, 2<\/code><\/pre>\n<p>\u0414\u0440\u0443\u0433\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 <code>tapOnce<\/code> \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432 <a href=\"https:\/\/medium.com\/javascript-everyday\/rxjs-taponce-operator-yet-another-solution-435f88e2484a\"><u>\u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u043c\u043e\u0438\u0445 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u043f\u043e\u0441\u0442\u043e\u0432<\/u><\/a>.<\/p>\n<h3>\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b<\/h3>\n<p>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>firstTruthy<\/code>:<\/p>\n<pre><code class=\"javascript\">import { MonoTypeOperatorFunction, of, pipe } from \"rxjs\"; import { first } from \"rxjs\/operators\";  const source1$ = of(0, \"\", \"foo\", 69);  function firstTruthy&lt;T&gt;(): MonoTypeOperatorFunction&lt;T&gt; {   return pipe(first(v =&gt; Boolean(v))); }  const result1$ = source1$.pipe(firstTruthy());  result1$.subscribe(console.log);  \/\/ console output: foo<\/code><\/pre>\n<p>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>evenMultiplied<\/code>:<\/p>\n<pre><code class=\"javascript\">import { interval, MonoTypeOperatorFunction, pipe } from \"rxjs\"; import { filter, map, take } from \"rxjs\/operators\";  const source2$ = interval(10).pipe(take(3));  function evenMultiplied(multiplier: number): MonoTypeOperatorFunction&lt;number&gt; {   return pipe(     filter(v =&gt; v % 2 === 0),     map(v =&gt; v * multiplier)   ); }  const result2$ = source2$.pipe(evenMultiplied(3));  result2$.subscribe(console.log);    \/\/ console output: 0, 6<\/code><\/pre>\n<p>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>liveSearch<\/code>:<\/p>\n<pre><code class=\"javascript\">import { ObservableInput, of, OperatorFunction, pipe  } from \"rxjs\"; import { debounceTime, delay, distinctUntilChanged, switchMap } from \"rxjs\/operators\";  const source3$ = of(\"politics\", \"sport\");  type DataProducer&lt;T&gt; = (q: string) =&gt; ObservableInput&lt;T&gt;;  function liveSearch&lt;R&gt;(   time: number,   dataProducer: DataProducer&lt;R&gt; ): OperatorFunction&lt;string, R&gt; {   return pipe(     debounceTime(time),     distinctUntilChanged(),     switchMap(dataProducer)   ); }  const newsProducer = (q: string) =&gt;   of(`Data fetched for ${q}`).pipe(delay(2000));  const result3$ = source3$.pipe(liveSearch(500, newsProducer));  result3$.subscribe(console.log);    \/\/ console output: Data fetched for sport<\/code><\/pre>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0422\u0438\u043f\u043e\u0432\u044b\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 RxJS \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0432 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0438 \u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u043f\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430. \u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u0432 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c\u044b\u0445 \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 pipe-\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>\u0416\u0438\u0432\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440: [\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0432 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u0435]<\/p>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0432\u0430\u043c \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u043b\u0441\u044f \u043c\u043e\u0439 \u043f\u043e\u0441\u0442 \u0438 \u0432\u044b \u0443\u0437\u043d\u0430\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u043d\u043e\u0432\u043e\u0435.<\/p>\n<hr>\n<blockquote>\n<p>\u041f\u0435\u0440\u0435\u0432\u043e\u0434 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043a\u0443\u0440\u0441\u0430 &#171;<a href=\"https:\/\/otus.pw\/cm96\/\"><strong>JavaScript Developer. Professional<\/strong><\/a>&#171;. \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u043e \u043a\u0443\u0440\u0441\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435, \u043f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u0435\u043c \u043d\u0430 <a href=\"https:\/\/otus.pw\/hAV6\/\">\u0434\u0435\u043d\u044c \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0445 \u0434\u0432\u0435\u0440\u0435\u0439<\/a> \u043e\u043d\u043b\u0430\u0439\u043d, \u0433\u0434\u0435 \u043f\u0440\u0435\u043f\u043e\u0434\u0430\u0432\u0430\u0442\u0435\u043b\u044c \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0435\u0442 \u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435.<\/p>\n<\/blockquote>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/562184\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/562184\/<\/a><br \/><\/br><\/br><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-324702","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/324702","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=324702"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/324702\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=324702"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=324702"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=324702"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}