Elm has two very common design patterns that both use pipeline function application.
Confusingly, both of them are commonly called the “builder” pattern!
Here’s what they are, how to tell them apart, and when to use them:
The first pattern is an interface for configuring data with optional values.
Button.newArgs initializes a
Button.Args with defaults:
This allows the user to set optional values by applying functions.
Builder #1 is commonly used:
- in UI code
- when optional configuration would make a function signature too cumbersome without it
The second pattern wraps a constructor function whose arguments are gradually applied by successive function calls.
Builder #2 is helpful for building up a value from data that could fail, like a JSON decoder or validator.