Challenge 2: Error Messages Using Maybe Monad
Explore how to apply the Maybe monad for error handling in PHP authentication functions. Learn to return structured error messages for invalid usernames or passwords and modify user data by adding roles and removing sensitive information. This lesson reinforces functional programming practices without using exceptions.
Problem statement
In the previous lesson, we eliminated exceptions by rewriting the authenticateUser function as a two-track Either monad-based function.
This time, you have to rewrite the function featured there to utilize Maybe monad case analysis.
Requirements
By maintaining all the requirements stated in the previous challenge, you have to perform the following additional requirement in order to complete the challenge:
- Convey each error message as an array with the
errorkey by using the Maybe monad.
To reiterate, the requirements were:
-
If the provided ...