Understand the Maybe Data Type

InstructorAndy Van Slaars

Share this video with your friends

Send Tweet

In this lesson, we’ll get started with the Maybe type. We’ll look at the underlying Just and Nothing types and create a simple utility function to create a Maybe from a value. Then we’ll see how we can apply functions to values and skip invocation for values that might cause errors or unexpected results.

Tre' Codez
Tre' Codez
~ 3 years ago

Loving it!

Tre' Codez
Tre' Codez
~ 3 years ago

I wonder how you've made vs code show your return values! Rather cool

Also, what theme is that?

Tulio Miranda
Tulio Miranda
~ 3 years ago

@Wayne, I've just searched for that (couldn't continue with the class knowing that there was something as awesome as that to be discovered). I found the QuokkaJs product ( made by the same team that built WallabyJs )

So, there you go!

Andy Van Slaars
Andy Van Slaars(instructor)
~ 3 years ago

Yup, it is Quokka from the Wallaby team.

The theme in the videos is this one: https://github.com/orefalo/bcmarinacci.theme-material-operator-1.3.0

Platon
Platon
~ 3 years ago

Hi, how do I get "Just" + return value or "Nothing" printed in the console instead of an unwrapped Maybe object (check the console output to this lesson, it's some object of type "crocks/Maybe@3")?

Invoking option(0) on a Just returns "Foo" as expected.

Andy Van Slaars
Andy Van Slaars(instructor)
~ 3 years ago

Hi, how do I get "Just" + return value or "Nothing" printed in the console instead of an unwrapped Maybe object (check the console output to this lesson, it's some object of type "crocks/Maybe@3")?

You can call it with the inspect method like this: console.log(result.inspect())

tsvika
tsvika
~ a year ago

Thanks Andy, There's a hype around ADT these days and I'm trying to understand it. As for Maybe shouldn't Typescript or Reason resolve these kind of issues? what's the added value?