November 2017
Intermediate to advanced
386 pages
9h 22m
English
What else are we missing? Let's see some other options that you might use. Union types are defined as a list of possible values. For example, our getField() function from Chapter 6, Producing Functions - Higher-Order Functions, either returns the value of an attribute, or it returns undefined. We can then write the following signature:
// getField :: String → attr → a | undefinedconst getField = attr => obj => obj[attr];
We could also define a type (union or otherwise) and later use it in further definitions. For instance, the data types that can be directly compared and sorted are numbers, strings, and booleans, so we could write the following definitions:
// Sortable :: Number | String | Boolean
Afterwards, we could specify ...
Read now
Unlock full access