Summing Up
Recursion, the ability of a function to call itself, lets you take finer control over processing collections. You don’t have to process every item, and the code can in some cases be more concise than using map or reduce. Most operations where you would use a loop in other languages are done via recursion in ReasonML. When you use recursion, you should make your functions tail recursive if at all possible so that ReasonML can optimize the code it generates. The ability to think recursively is a great skill to add to your programmer’s toolkit.
In the next chapter, we’ll return to the world of data types. We’ll investigate records in ReasonML, which let you make a data structure that contains multiple data types. Additionally, we’ll ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access