Structs
Explore how Elixir's structs create typed maps with fixed, atom-based keys and default values. Understand how to define, access, update, and use structs within modules to add behavior, enhancing your functional programming skills.
We'll cover the following...
We'll cover the following...
Why do we need structs?
When Elixir sees %{ ... }, it knows it’s looking at a map. But it doesn’t know much more than that. In particular, it doesn’t know what we intend to do with the map, whether only certain keys are allowed, or whether some keys should have default values. That’s fine for anonymous maps. But what if we want to create a typed map? A typed map has a fixed set of fields and default values for those fields, and we can pattern match ...