Why are Booleans bad?
Question
I heard that Booleans should be avoided in Elm, How and Why?
Answer
Booleans create a lot of problems, for example what does it mean if Request.fetching
is False
but Request.message
has some value? Or how can one know what the returned boolean of getResponse
stands for? The type system of Elm can avoid such problems:
Use
Maybe (String, Bool)
instead of returning some default value.Use
Result String String
to handle resultsUse a Custom Type and Patter Matching instead of
Request.fetching
and If-Statements.
Further reading
🎥Video: Solving the Boolean Identity Crisis by Jeremy Fairbank
📄Article: Solving the Boolean Identity Crisis Part 1 by Jeremy Fairbank
📄Article: Solving the Boolean Identity Crisis Part 2 by Jeremy Fairbank
Last updated