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.
Solution: Generating random cakes - ReasonML Tutorial
From the course: ReasonML: First Look
Solution: Generating random cakes
- [Instructor] This challenge involved two main parts. You had to complete the Cake.re Module by providing a toString function. And then you had to add code to the CakeExamples.re file to create Random Cakes. First let's look at toString. We can use the existing toString functions in our sub modules for most of the record's fields. For the Size, the Flavor and the Frosting. Since the Filling is an option field we need to use a switch expression to handle both cases. When there's a Filling and when there isn't one. The number of Layers as a integer and the message is already a string, and this function uses the plus, plus concatenation operator to tie every thing together. In the CakeExamples.re file we've created Arrays containing the valid choices for each of the data type constructor values for the size, the flavor, the frosting, filling and messages. Here's a function that takes an Array as it's argument and gets…
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)
-
-