Search⌘ K

Inspect

Explore how to implement Elixir's Inspect protocol to produce readable, valid Elixir representations of data. Learn to use algebra documents to format and pretty-print complex data structures with indentation and line wrapping, improving output clarity.

Introduction

This is the protocol that’s used to inspect a value. The rule is simple. If we can return a representation that’s a valid Elixir literal, do so. Otherwise, prefix the representation with #Typename.

We could just delegate the inspect function to the Elixir default. That’s what we’ve been doing so far. But we can do better. Not surprisingly, we do that by implementing the Inspect protocol. We’ll ...