Hi,
I am new to Elm and I have a function that returns a list with elements.
I want to edit this function to return a single element list with a text if the list is empty.
E.g “Could not retrieve list for you”
Original code
viewResults : RemoteData.WebData (List KartverketResult) -> Html Msg
viewResults data =
case data of
RemoteData.NotAsked ->
text ""
RemoteData.Loading ->
text ""
RemoteData.Success results ->
results
|> List.map viewResult
|> ul [ class "col-1of1 border_search_list" ]
RemoteData.Failure e ->
text "Sorry, could not retrieve list. Some error occurde"
Ish what I wish, that Elm does not want to do for me:
viewResults : RemoteData.WebData (List KartverketResult) -> Html Msg
viewResults data =
case data of
RemoteData.NotAsked ->
text ""
RemoteData.Loading ->
text ""
RemoteData.Success results ->
if List.isEmpty results then
li [ class "col-1of1 txt-primary padding-5" ] [ text "List is empty, Please check your spelling" ]
|> ul [ class "col-1of1 border_search_list" ]
else
results
|> List.map viewResult
|> ul [ class "col-1of1 border_search_list" ]
RemoteData.Failure e ->
text "Sorry, could not retrieve list. Some error occurde"
tl;dr
RemoteData.Success results ->
results
|> List.map viewResult
|> ul [ ]
Code above to code below
RemoteData.Success results ->
if List.isEmpty results then
li [ ] [ text "List is empty, Please check your spelling" ]
|> ul [ ]
else
results
|> List.map viewResult
|> ul [ ]
Kind Regards,
Simon