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

Solution: Generating random cakes - ReasonML Tutorial

From the course: ReasonML: First Look

Start my 1-month free trial

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…

Contents