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 - ReasonML Tutorial
From the course: ReasonML: First Look
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
Creating your own data types5m 10s
-
(Locked)
Say goodbye to null and undefined4m 39s
-
(Locked)
Creating modules for reusable code2m 35s
-
(Locked)
Using collection types6m 41s
-
(Locked)
Creating record types6m 47s
-
(Locked)
Challenge: Generating random cakes2m 1s
-
(Locked)
Solution: Generating random cakes2m 57s
-
(Locked)
-
-