concept Maybe.andThen in category elm

appears as: Maybe.dThen
Elm in Action

This is an excerpt from Manning's book Elm in Action.

Whenever we have two nested case-expressions like this, with both of them handling Nothing the same way, Maybe.andThen does exactly the same thing as the code we had before.

We’ll use Maybe.andThen when we define selectedPhoto in our actual view function. Let’s replace our existing view function with the following definition.

Listing 7.5. Implementing view using Maybe.andThen
view : Model -> Html Msg
view model =
    let
        photoByUrl : String -> Maybe Photo                           #1
        photoByUrl url =                                             #1
            Dict.get url model.photos                                #1

        selectedPhoto : Html Msg
        selectedPhoto =
            case Maybe.andThen photoByUrl model.selectedPhotoUrl of
                Just photo ->                                        #2
                    viewSelectedPhoto photo                          #2

                Nothing ->
                    text ""
    in
    div [ class "content" ]                                          #3
        [ div [ class "selected-photo" ] [ selectedPhoto ] ]         #3