โ ๏ธ This post links to an external website. โ ๏ธ
Before we talk about data structures, it helps to name a problem youโve likely encountered in other languages. You call a function that tries to find a user in a database. If the user exists, you get a
Userobject. If they donโt, you getnullornil.This feels fine until you need to know why something failed. Did the user not exist, or did the database connection time out? Suddenly youโre returning magic strings, throwing exceptions, or checking boolean flags. The code becomes a minefield of if statements checking for special cases.
In Elixir, we solve this by treating data structures as contracts. We donโt just return a value. We return a structure that explicitly declares what happened.
continue reading ongrox.io
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.