What are Elixir structs?
Answer
Structs in Elixir are typed maps with compile-time key checking and default values. Define inside a module: defmodule User do; defstruct name: nil, age: 0, active: true; end. Create: user = %User{name: "Alice", age: 30}. Access: user.name. Update: %{user | age: 31}. Unlike plain maps, structs have a defined set of keys — accessing an undefined key is a compile-time error. Pattern match: %User{name: name} = user. Structs have a __struct__ field that contains the module name, enabling pattern matching by type: %User{} = user. They can implement Elixir protocols (like String.Chars, Inspect). Structs are used to represent domain entities, configuration, and any typed data. They are essentially named maps — the underlying data is still a map, but with validation and better introspection.