Skip to Main Content
ReasonML Quick Start Guide
book

ReasonML Quick Start Guide

by Raphael Rafatpanah, Bruno Joseph D'mello
February 2019
Beginner to intermediate content levelBeginner to intermediate
180 pages
4h 4m
English
Packt Publishing
Content preview from ReasonML Quick Start Guide

Testing business logic

Let's write a test that verifies we're able to get the right customer by its id. In Customer.re, there is a function called getCustomer that accepts an array of customers, and imperatively gets the id by calling getId. The getId function accepts a pathname that exists outside the scope of getCustomer:

let getCustomer = customers => {  let id = getId(pathname);  customers |> Js.Array.find(customer => customer.CustomerType.id == id);};

Right away, we notice that this is less than ideal. It would be much better if getCustomer accepted an array of customers and an id, and focused on getting the customer by their id. Otherwise, it will be harder to write a test just for getCustomer.

So, we refactor getCustomer to also accept ...

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.
Start your free trial

You might also like

Reinventing the Organization for GenAI and LLMs

Reinventing the Organization for GenAI and LLMs

Ethan Mollick
Expert F# 4.0, Fourth Edition

Expert F# 4.0, Fourth Edition

Don Syme, Adam Granicz, Antonio Cisternino
Learn Type-Driven Development

Learn Type-Driven Development

Soumya Mukherjee, Yawar Amin, Kamon Ayeva

Publisher Resources

ISBN: 9781789340785Supplemental Content