Create upwards compatible APIs
This topic has been covered by Elm Patterns
Movie.elm
Question
How can I define my type, such that I can add features without breaking the API?
Answer
First write a constructor fromTitle
that only uses as few arguments as possible.
Next add partial constructors for every feature of your type: withRating
and withDirector
.
Now creating a new Movie
can be done like this:
Further Reading
📄Article: With* Functions in Elm by Charlie Koster
🎥Video: Robot Buttons from Mars by Brian Hicks
❗Example: NoRedInk/elm-json-decode-pipeline
❗Example: Chadtech/random-pipeline
❗Example: Particle Type from BrianHicks/elm-particle
❗Example: Request Type from dillonkearns/elm-graph
❗Example: Image Type from Orasund/pixelengine
Last updated