> For the complete documentation index, see [llms.txt](https://chasethestar.gitbook.io/ko.learn-rxjs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://chasethestar.gitbook.io/ko.learn-rxjs/rxjs/operators/utility/do.md).

# tap / do

#### signature: `tap(nextOrObserver: function, error: function, complete: function): Observable`

## Transparently perform actions or side-effects, such as logging.

***

💡 If you are using as a pipeable operator, `do` is known as `tap`!

***

[![Ultimate RxJS](https://drive.google.com/uc?export=view\&id=1qq2-q-eVe-F_-d0eSvTyqaGRjpfLDdJz)](https://ultimatecourses.com/courses/rxjs?ref=4)

### Examples

**Example 1: Logging with tap**

( [StackBlitz](https://stackblitz.com/edit/typescript-cd2gjp?file=index.ts\&devtoolsheight=100) | [jsBin](http://jsbin.com/jimazuriva/1/edit?js,console) | [jsFiddle](https://jsfiddle.net/btroncone/qtyakorq/) )

```js
// RxJS v6+
import { of } from 'rxjs';
import { tap, map } from 'rxjs/operators';

const source = of(1, 2, 3, 4, 5);
// transparently log values from source with 'tap'
const example = source.pipe(
  tap(val => console.log(`BEFORE MAP: ${val}`)),
  map(val => val + 10),
  tap(val => console.log(`AFTER MAP: ${val}`))
);

//'tap' does not transform values
//output: 11...12...13...14...15
const subscribe = example.subscribe(val => console.log(val));
```

**Example 2: Using tap with object**

( [StackBlitz](https://stackblitz.com/edit/typescript-3xykpb?file=index.ts\&devtoolsheight=100))

```js
// RxJS v6+
import { of } from 'rxjs';
import { tap, map } from 'rxjs/operators';

const source = of(1, 2, 3, 4, 5);

// tap also accepts an object map to log next, error, and complete
const example = source
  .pipe(
    map(val => val + 10),
    tap({
      next: val => {
        // on next 11, etc.
        console.log('on next', val);
      },
      error: error => {
        console.log('on error', error.message);
      },
      complete: () => console.log('on complete')
    })
  )
  // output: 11, 12, 13, 14, 15
  .subscribe(val => console.log(val));
```

### Related Recipes

* [Battleship Game](/ko.learn-rxjs/rxjs/recipes/battleship-game.md)
* [Breakout Game](/ko.learn-rxjs/rxjs/recipes/breakout-game.md)
* [Car Racing Game](/ko.learn-rxjs/rxjs/recipes/car-racing-game.md)
* [Catch The Dot Game](/ko.learn-rxjs/rxjs/recipes/catch-the-dot-game.md)
* [Click Ninja Game](/ko.learn-rxjs/rxjs/recipes/click-ninja-game.md)
* [Flappy Bird Game](/ko.learn-rxjs/rxjs/recipes/flappy-bird-game.md)
* [Horizontal Scroll Indicator](/ko.learn-rxjs/rxjs/recipes/horizontal-scroll-indicator.md)
* [Lockscreen](/ko.learn-rxjs/rxjs/recipes/lockscreen.md)
* [Memory Game](/ko.learn-rxjs/rxjs/recipes/memory-game.md)
* [Mine Sweeper Game](/ko.learn-rxjs/rxjs/recipes/mine-sweeper-game.md)
* [Platform Jumper Game](/ko.learn-rxjs/rxjs/recipes/platform-jumper-game.md)
* [Save Indicator](/ko.learn-rxjs/rxjs/recipes/save-indicator.md)
* [Space Invaders Game](/ko.learn-rxjs/rxjs/recipes/space-invaders-game.md)
* [Stop Watch](/ko.learn-rxjs/rxjs/recipes/stop-watch.md)
* [Swipe To Refresh](/ko.learn-rxjs/rxjs/recipes/swipe-to-refresh.md)
* [Tank Battle Game](/ko.learn-rxjs/rxjs/recipes/tank-battle-game.md)
* [Tetris Game](/ko.learn-rxjs/rxjs/recipes/tetris-game.md)
* [Type Ahead](/ko.learn-rxjs/rxjs/recipes/type-ahead.md)
* [Uncover Image Game](/ko.learn-rxjs/rxjs/recipes/uncover-image-game.md)

### Additional Resources

* [tap](https://rxjs.dev/api/operators/tap) 📰 - Official docs
* [tap](https://indepth.dev/reference/rxjs/operators/tap) - In Depth Dev Reference
* [Logging a stream with do](https://egghead.io/lessons/rxjs-logging-a-stream-with-do?course=step-by-step-async-javascript-with-rxjs) 🎥 💵 - John Linquist
* [Utility operator: do](https://egghead.io/lessons/rxjs-utility-operator-do?course=rxjs-beyond-the-basics-operators-in-depth) 🎥 💵 - André Staltz
* [Build your own tap operator](https://blog.strongbrew.io/build-the-operators-from-rxjs-from-scratch/?lectureId=tap#app) 🎥 - Kwinten Pisman

***

> 📁 Source Code: <https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/tap.ts>
