January 2020
Intermediate to advanced
470 pages
11h 13m
English
What else are we missing? Let's look at some other options that you might use. Product types are a set of values that are always together and are commonly used with objects. For tuples (that is, an array with a fixed number of elements of (probably) different types), we can write something like the following:
// getWeekAndDay :: String → (Number × String)const getWeekAndDay = yyyy_mm_dd => /* ... */ return [weekNumber, dayOfWeekName];
For objects, we can go with a definition very similar to what JavaScript already uses. Let's imagine we have a getPerson() function that receives an ID and returns an object with data about a person:
// getPerson :: Number → { id:Number × name:String }const getPerson = personId => ...Read now
Unlock full access