From the course: ReasonML: First Look

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Say goodbye to null and undefined

Say goodbye to null and undefined - ReasonML Tutorial

From the course: ReasonML: First Look

Start my 1-month free trial

Say goodbye to null and undefined

- [Instructor] In a previous video, we converted a cake size value to a string. Here's the code that does that. Now, it's time to go in the opposite direction, converting a string to a cake size. We'll let cake size from string be a function that takes a string and returns a cake size type. We'll do a switch on the lowercase version of the input and when the string is full, that's a full size cake type, and similarly for half and quarter. Reason tells us that we haven't covered all the possible cases. We need our catch all case for all other strings, but we can't return null, or undefined, because those key words don't exist in Reason. Instead, Reason has something called the option type. An expression of an option type can either be some value for example, an optional age can be some value like 22 or if we have something that's not assigned yet or invalid we say, there's no valid value yet, none. The apostrophe a is…

Contents