title: Wrap an Observable. Do something before and after each emitted value
body: <p>I'd like to build a wrapper class, that does something before and after each emitted value of an Observable.</p>
  
  <p>Here's what I came up with:</p>
  
  <pre><code>class Wrapper&lt;T&gt; {
      wrapped$: Observable&lt;T&gt;;
  
      _dataSubject = new Subject&lt;T&gt;();
      data$ = this._dataSubject.pipe(
          tap(_ =&gt; console.log("BEFORE"),
          //
          // map( ??? )
          //
      );
  
      constructor(wrapped$: Observable&lt;T&gt;) {
          this.wrapped$ = wrapped$.pipe(
              tap(_ =&gt; console.log("AFTER")
          );
      }
  }
  
  let subject = new Subject&lt;string&gt;();
  let wrapper = new Wrapper(subject);
  wrapper.data$.subscribe(val =&gt; console.log(val));
  subject.next("foo")
  </code></pre>
  
  <p>The console output should be:</p>
  
  <pre><code>BEFORE
  foo
  AFTER
  </code></pre>
  
  <p>I can't figure out how to connect the <code>$wrapped</code> Observable with the <code>_dataSubject</code>.</p>
  
  <p>But maybe I'm completely wrong and it needs a different approach.</p>