If you're unfamiliar with the
Maybe type, it is a data type (an ADT or Algebraic Data Type) that wraps values and makes it safe to operate on a value without having to scatter conditionals throughout your code.
When values have the potential to change types or to end up as
undefined, that can lead to runtime errors in our code or bizarre bugs that take forever to track down thanks to type coercion. To battle this, we end up with code that is littered with conditionals for
undefined values and type checks, making the core logic harder to read and refactor later.
Maybe encapsulates the type checking and guards against missing values for us. With
Maybe in our tool belt, we can keep our functions free of all the guardrails, outsource that work to the
Maybe and keep our business logic free of all the clutter.
You can follow along from this article, as I will update it with lists as each new entry in the series is published.