O'Reilly logo

Programming Elm by Jeremy Fairbank

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Remove View Duplication

Now that you’ve split Msg, Model, and update into manageable pieces, you need to return to the view layer. In this section, you will create reusable helper functions to eliminate the excessive code duplication in viewBuild and make it easier to create new form inputs in the future.

Create a Reusable Section

Removing the input duplication will be tricky, so let’s start with the form sections. Notice that you repeat a section tag with a "salad-section" class name. Each of these sections has an h2 heading and form input content. First, you extract the creation of a form section into a reusable function. Add a viewSection function above viewBuild like so:

 viewSection : ​String​ -> ​List ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required