Restrict records using Opaque Types
This topic has been covered by Elm Patterns
If you're writing a package use a pipeline API instead.
Main.elm
Question
How can I only allow specific states for my type?
Answer
Place the type into a new File and don't expose the constructor: exposing (Movie)
instead of exposing(Movie(..))
.
Then write your own constructors.
We can unwrap function parameters like this:
Further reading
📖Book: Beginning Elm by Pawan Poudel
📄Article: Advanced Types in Elm - Opaque Types by Charlie Koster
👥Thread: Post-update invariant repair: good idea or bad?
Last updated