Choosing Configs

Learn about the difference between Alt and Alternative and how to use monoids for config in our application.

Alt and Alternative

We dealt with a tiny configuration in our Create Lambda. Often, though, applications have not only much bigger configs, but also various defaults to fall back to. We might have default program settings that are overwritten by system settings, and overwritten by specific user settings. Are there elegant ways to handle such a situation, preferably without too much conditional branching? For easy scenarios, we might consider using Alt and Alternative. Alt is similar to semigroup, except that it can work with monads. Alternative is Alt expanded with an identity element. This is similar to the way monoids add an empty value to a semigroup.

Take a look at this example:

Get hands-on with 1200+ tech skills courses.