DEV Community

Discussion on: NULL, "The Billion Dollar Mistake", Maybe Just Nothing

Collapse
 
dmh2000 profile image
david howard

I get it that using Maybe prevents a null reference from crashing the program, but now you get a Nothing that's also unexpected. Is the philosophy then that you need to guard for Nothing or that it is just considered a lesser bug that needs to be fixed but at least doesn't kill the app. Or?

Collapse
 
joelnet profile image
JavaScript Joel • Edited

It changes from null being expected to. A Maybe being expected. So Nothing is a valid input.

When you use map, it will work on both a Just and a Nothing.

So you can stop guards completely!

This is a good example of what I am talking about:

const toUpper = string => string.toUpperCase()

map (toUpper) (Just ("abc")) //=> Just ('ABC')
map (toUpper) (Nothing) //=> Nothing

You don't have to worry about if the value is a Just or a Nothing. You just accept a Maybe.