alex-tan/elm-review-opinionated-simplify/1.0.0

PreferMaybeChaining

Prefer Maybe.map, Maybe.andThen, and Maybe.withDefault over case expressions.

rule : Rule

Reports case expressions on Maybe that can be simplified.

config =
    [ PreferMaybeChaining.rule
    ]

Fail

case maybeValue of
    Nothing ->
        Nothing


    Just x ->
        Just (f x)


case maybeValue of
    Nothing ->
        Nothing


    Just x ->
        lookup x


case maybeValue of
    Nothing ->
        defaultValue


    Just x ->
        x

Success

Maybe.map f maybeValue


Maybe.andThen lookup maybeValue


Maybe.withDefault defaultValue maybeValue


Maybe.Extra.withDefaultLazy (\() -> complexExpr) maybeValue

Try it out

You can try this rule out by running the following command:

elm-review --template alex-tan/elm-review-opinionated-simplify/example --rules PreferMaybeChaining