Isn't Nothing just the concept of undefined? What's stopping me from just comparing to undefined
Also, no, nothing is not the concept of undefined.
I'm not against the idea, I just think this is maybe better as a Type in Typescript then a class. No need to complicate which can be just:
Maybe = T | undefined
Or maybe I haven't understood this completely, will have a look at some more articles.
Yeah I don't think I'm able to explain the idea to you well enough; I hope you find the right resources online! Just to set the right context; no; you will not have to add any checks if you're using ADTs and mapping over them. The reason to use them is to remove all these unnecessary checks.
I think is more about returning a meaningful "empty" value, one that doesn't stop execution in unexpected ways. That's half the story, like many patterns in functional programming, this one encourages extension through function composition. Maybe a more practical example could help you see it, I wrote this one last year.
It's a valid question as this post doesn't put Maybe into context. It's very un-clean to litter your code with null checks etc; moreover, it's not very mathematical to have functions that are that unpredictable. Another reason is inversion of control. The ecosystem around Maybe/Either etc in functional JS is enables the caller of a function to do error management independently, outside of that function, i.e. no more try-catches, no more checking types of returned values, just pattern matching on the returned type if it's an Either.
I've been using Ramda long before I started using Eithers and Maybes and ever since I switched to using ADTs my Ramda composition pipelines have become more succinct, more "clean" and more predictable.
Maybe I don't make any sense, But if you read the replies to Drew's comments and go through Brian Lonsdorf's linked tutorial; it will help you discover a new paradigm of making predictable apps with JS that are easier to reason about.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.