# Recipe: Debugging with toString

If you need to print out the data in your process, the easiest way is to dump the content out to stdout. This tip came from the youtube video: Intro to FS2 - Part3: Concurrency.

The key idea is that to dump data for inspection, you can define a pipe that passes the data through untouched, but as a side effect, prints the data using a println statement. Since println is IO, its an effect we need to manage in a `F[_]`.

```scala
fs2> def log[A](prefix: String): Pipe[Task, A,A] = _.evalMap{ a => Task.delay{ println(s"$prefix> $a"); a}} 
defined function log
```

then just pass the content through the pipe.

`log` works by mapping into the input stream and evaluating (through `eval`) the effect inside, which is a Task that prints out the debug message. The syntax `_.evalMap` is just a way to declare a function. The `_` says take whatever is given as input and map into it. Because we specifically added the type information to `log`, the scala compiler knew it needed a function definition (a Pipe is just a function `Stream[F[_], I] => Stream[F[_], O]` and combined with `_`, it found one.

In the example below, we use `run` because we are not interested in the output:

```scala
fs2> Stream.range(1,10).through(log("logger")).run.unsafeRun 
logger> 1
logger> 2
logger> 3
logger> 4
logger> 5
logger> 6
logger> 7
logger> 8
logger> 9
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://devon-miller.gitbook.io/test_private_book/miscellaneous/recipe-debugging-with-tostring.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
