devleo
devleo

Reputation: 1195

Debugging Elixir streams

I am new to Elixir and I would like to learn how to debug Streams better.

It's common where I work to have operations performed on large datasets. This means that Streams are used heavily until the final operation, usually an Enum.sum().

But this unfortunately means several calls look indecipherable as they are composed of several undocumented Stream.map functions. (a problem we are currently fixing). I would like to see the state of the data as it passes from stream to stream for debugging. How is this normally accomplished?

Example:

SomeModule.some_large_call_that_returns_a_stream()
|> Stream.map(some_huge_hard_to_read_thing)
|> Stream.map(some_huge_hard_to_read_thing)
|> Stream.map(some_huge_hard_to_read_thing)
|> Enum.sum()

This is difficult to debug looking at the result, especially if Enum.sum() returns no value or 0.

Any suggestions? And the debugger is currently unavailable to me.

Upvotes: 1

Views: 484

Answers (1)

Kociamber
Kociamber

Reputation: 1155

Would it be enough to start with connecting IO.inspect/2 to your pipeline? ie:

SomeModule.some_large_call_that_returns_a_stream()
|> Stream.map(some_huge_hard_to_read_thing)
|> Stream.map(some_huge_hard_to_read_thing)
|> Stream.map(&IO.inspect/1)
|> Stream.map(some_huge_hard_to_read_thing)
|> Enum.sum()

Upvotes: 6

Related Questions