Our world is full of uncertainty. This uncertainty bleeds into our programs.
Constantly checking the presence of every value is a lot of work so we tend to only check the riskiest places and then have to deal with runtime null exceptions in the rest of our code. Elm and many other languages use a different approach to dealing with uncertainty: Maybe.
In Elm, all values are guaranteed to be present except for those wrapped in a Maybe. This is a critical distinction.
You can now be confident in most of your code and the compiler will force you to make presence-checks in places where values are optional. Unfortunately, this can quickly devolve into a nightmare of nested case statements.
Lookijg example, say you have a list of users and you want to uppercase the name of the first friend of the first user. This is typically done by providing some default value. With the helper function Maybe.
Often there is no sensible default value so you just want to re-wrap in Maybe after doing a calculation. Isolating the first step of our big case statement getting the friends of the first user we might say:. This keeps propagating the Maybe forward down the chain.
Isolating the second step of our big case statement getting the first friend might look like:. That means using map here would result in a doubly-nested maybe which is not what we wanted.
Instead, we can use the Maybe. Looking at a more extreme case, say we wanted to get at the head of the inner list [[[[1, 2]]]] using repeated uses of List. Notice that each step is only a single Just deep, no matter how somethinb times we chain.
Lonely Adult Wanting Free Sex Dating Chat I'm Looking For Fuck Buddy Looking for fun maybe something else
So when do you want to use map vs andThen? In our example above.
A closer look usually reveals that they conform to one of the three patterns shown earlier. Nested branching logic, error handling, and duplicated run make it very difficult to follow the logic here. Combine them all into a pipeline and we get:.
Horny Mom Search Hot Moms You Work In The Lonely Married Woman Sexy Granny Chat Mall Looking for fun maybe something else
This is much nicer to read but someting still equivalent to the case statement. Software de and development requires collaborative efficiency—the ability to quickly solve problems together. When a team is remote, productivity can plummet.
Maybe Elm and many other languages use a different approach to dealing with uncertainty: Maybe. Empower your teams to work remotely with thoughtbot Software de and development requires collaborative efficiency—the ability to quickly solve problems together. Learn more about somethinng up.