Add a clause to a case expression in a specified function
in a specified module. For example, if you put the code below in your
ReviewConfig.elm file, running elm-review --fix will add the clause
ResetCounter to the updateFromFrontend function in the Backend module.
-- code for ReviewConfig.elm:
Install.ClauseInCase.config "Backend" "updateFromFrontend" "ResetCounter" "( { model | counter = 0 }, broadcast (CounterNewValue 0 clientId) )"
|> Install.ClauseInCase.makeRule
Thus we will have
updateFromFrontend : SessionId -> ClientId -> ToBackend -> Model -> ( Model, Cmd BackendMsg )
updateFromFrontend sessionId clientId msg model =
case msg of
CounterIncremented ->
...
CounterDecremented ->
...
ResetCounter ->
( { model | counter = 0 }, broadcast (CounterNewValue 0 clientId) )
You also can add the clause after another clause of choice with the `withInsertAfter` function:
Install.ClauseInCase.config "Backend" "updateFromFrontend" "ResetCounter" "( { model | counter = 0 }, broadcast (CounterNewValue 0 clientId) )"
|> Install.ClauseInCase.withInsertAfter "CounterIncremented"
|> Install.ClauseInCase.makeRule
In this case we will have
updateFromFrontend : SessionId -> ClientId -> ToBackend -> Model -> ( Model, Cmd BackendMsg )
updateFromFrontend sessionId clientId msg model =
case msg of
CounterIncremented ->
...
ResetCounter ->
( { model | counter = 0 }, broadcast (CounterNewValue 0 clientId) )
CounterDecremented ->
...
You can also customize the error message with the `withCustomErrorMessage` function:
Install.ClauseInCase.config "Backend" "updateFromFrontend" "ResetCounter" "( { model | counter = 0 }, broadcast (CounterNewValue 0 clientId) )"
|> Install.ClauseInCase.withCustomErrorMessage "Add handler for ResetCounter" []
|> Install.ClauseInCase.makeRuleCreate a makeRule that adds a clause to a case expression in a specified function. You can use it like this:
Install.ClauseInCase.config "Backend" "updateFromFrontend" "ResetCounter" "( { model | counter = 0 }, broadcast (CounterNewValue 0 clientId) )"
|> Install.ClauseInCase.makeRuleAdd a clause after another clause of choice in a case expression. If the clause to insert after is not found, the new clause will be inserted at the end.
Given the following module:
module Philosopher exposing (Philosopher(..), stringToPhilosopher)
type Philosopher
= Socrates
| Plato
| Aristotle
stringToPhilosopher : String -> Maybe Philosopher
stringToPhilosopher str =
case str of
"Socrates" ->
Just Socrates
"Plato" ->
Just Plato
"Aristotle" ->
Just Aristotle
_ ->
NothingTo add the clause Aspasia after the clause Aristotle, you can use the following configuration:
Install.ClauseInCase.config "Philosopher" "stringToPhilosopher" "Aspasia" "Just Aspasia"
|> Install.ClauseInCase.withInsertAfter "Aristotle"
|> Install.ClauseInCase.makeRuleThis will add the clause Aspasia after the clause Aristotle in the stringToPhilosopher function, resulting in:
stringToPhilosopher : String -> Maybe Philosopher
stringToPhilosopher str =
case str of
"Socrates" ->
Just Socrates
"Plato" ->
Just Plato
"Aristotle" ->
Just Aristotle
"Aspasia" ->
Just Aspasia
_ ->
NothingAdd a clause at the beginning of the case expression.
Customize the error message that will be displayed when running elm-review --fix or elm-review --fix-all
Configuration for makeRule: add a clause to a case expression in a specified function in a specified module.
Custom error message to be displayed when running elm-review --fix or elm-review --fix-all
Basic config to add a new clause to a case expression. If you just need to add a new clause at the end of the case, you can simply use it with the
makeRulefunction like this: