Use Extensible Records
Now that you’ve organized the salad state, you need to handle the contact-related state. You’ve seen the pitfalls of nested state. In this section, you will learn a different approach by using extensible records to create a Contact type without nesting state. Yet, you will still build a separate updateContact function that only changes contact-related fields.
Extract the Contact
You need to make a Contact type alias, but it will differ from the type aliases you’ve made previously. Below the Salad type alias, add this code:
| type alias Contact c = |
| { c |
| | name : String |
| , email : String |
| , phone : String |
| } |
This is an extensible record type. An extensible record resembles ...
Get Programming Elm now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.